Commit 404be18c authored by Bas de Nooijer's avatar Bas de Nooijer

Various code standard fixes

parent e28de900
...@@ -265,7 +265,9 @@ class Client extends Configurable ...@@ -265,7 +265,9 @@ class Client extends Configurable
$this->endpoints[$key] = $endpoint; $this->endpoints[$key] = $endpoint;
// if no default endpoint is set do so now // if no default endpoint is set do so now
if (null == $this->defaultEndpoint) $this->defaultEndpoint = $key; if (null == $this->defaultEndpoint) {
$this->defaultEndpoint = $key;
}
} }
return $this; return $this;
...@@ -300,9 +302,11 @@ class Client extends Configurable ...@@ -300,9 +302,11 @@ class Client extends Configurable
*/ */
public function getEndpoint($key = null) public function getEndpoint($key = null)
{ {
if (null == $key) $key = $this->defaultEndpoint; if (null == $key) {
$key = $this->defaultEndpoint;
}
if (!isset($this->endpoints[$key])){ if (!isset($this->endpoints[$key])) {
throw new Exception('Endpoint '.$key.' not available'); throw new Exception('Endpoint '.$key.' not available');
} }
...@@ -497,7 +501,9 @@ class Client extends Configurable ...@@ -497,7 +501,9 @@ class Client extends Configurable
// support both "key=>value" and "(no-key) => array(key=>x,query=>y)" formats // support both "key=>value" and "(no-key) => array(key=>x,query=>y)" formats
if (is_array($class)) { if (is_array($class)) {
if (isset($class['type'])) $type = $class['type']; if (isset($class['type'])) {
$type = $class['type'];
}
$class = $class['query']; $class = $class['query'];
} }
...@@ -555,7 +561,9 @@ class Client extends Configurable ...@@ -555,7 +561,9 @@ class Client extends Configurable
{ {
foreach ($plugins as $key => $plugin) { foreach ($plugins as $key => $plugin) {
if (!isset($plugin['key'])) $plugin['key'] = $key; if (!isset($plugin['key'])) {
$plugin['key'] = $key;
}
$this->registerPlugin( $this->registerPlugin(
$plugin['key'], $plugin['key'],
...@@ -678,7 +686,9 @@ class Client extends Configurable ...@@ -678,7 +686,9 @@ class Client extends Configurable
public function createRequest(QueryInterface $query) public function createRequest(QueryInterface $query)
{ {
$pluginResult = $this->callPlugins('preCreateRequest', array($query), true); $pluginResult = $this->callPlugins('preCreateRequest', array($query), true);
if($pluginResult !== null) return $pluginResult; if($pluginResult !== null) {
return $pluginResult;
}
$requestBuilder = $query->getRequestBuilder(); $requestBuilder = $query->getRequestBuilder();
if (!$requestBuilder || !($requestBuilder instanceof RequestBuilderInterface)) { if (!$requestBuilder || !($requestBuilder instanceof RequestBuilderInterface)) {
...@@ -702,7 +712,9 @@ class Client extends Configurable ...@@ -702,7 +712,9 @@ class Client extends Configurable
public function createResult(QueryInterface $query, $response) public function createResult(QueryInterface $query, $response)
{ {
$pluginResult = $this->callPlugins('preCreateResult', array($query, $response), true); $pluginResult = $this->callPlugins('preCreateResult', array($query, $response), true);
if($pluginResult !== null) return $pluginResult; if ($pluginResult !== null) {
return $pluginResult;
}
$resultClass = $query->getResultClass(); $resultClass = $query->getResultClass();
$result = new $resultClass($this, $query, $response); $result = new $resultClass($this, $query, $response);
...@@ -726,7 +738,9 @@ class Client extends Configurable ...@@ -726,7 +738,9 @@ class Client extends Configurable
public function execute(QueryInterface $query, $endpoint = null) public function execute(QueryInterface $query, $endpoint = null)
{ {
$pluginResult = $this->callPlugins('preExecute', array($query), true); $pluginResult = $this->callPlugins('preExecute', array($query), true);
if($pluginResult !== null) return $pluginResult; if ($pluginResult !== null) {
return $pluginResult;
}
$request = $this->createRequest($query); $request = $this->createRequest($query);
$response = $this->executeRequest($request, $endpoint); $response = $this->executeRequest($request, $endpoint);
...@@ -920,7 +934,9 @@ class Client extends Configurable ...@@ -920,7 +934,9 @@ class Client extends Configurable
$type = strtolower($type); $type = strtolower($type);
$pluginResult = $this->callPlugins('preCreateQuery', array($type, $options), true); $pluginResult = $this->callPlugins('preCreateQuery', array($type, $options), true);
if($pluginResult !== null) return $pluginResult; if($pluginResult !== null) {
return $pluginResult;
}
if (!isset($this->queryTypes[$type])) { if (!isset($this->queryTypes[$type])) {
throw new Exception('Unknown querytype: '. $type); throw new Exception('Unknown querytype: '. $type);
......
...@@ -151,7 +151,9 @@ class Endpoint extends Configurable ...@@ -151,7 +151,9 @@ class Endpoint extends Configurable
*/ */
public function setPath($path) public function setPath($path)
{ {
if (substr($path, -1) == '/') $path = substr($path, 0, -1); if (substr($path, -1) == '/') {
$path = substr($path, 0, -1);
}
return $this->setOption('path', $path); return $this->setOption('path', $path);
} }
......
...@@ -219,8 +219,11 @@ class Request extends Configurable ...@@ -219,8 +219,11 @@ class Request extends Configurable
$this->params[$key][] = $value; $this->params[$key][] = $value;
} else { } else {
// not all solr handlers support 0/1 as boolean values... // not all solr handlers support 0/1 as boolean values...
if($value === true) $value = 'true'; if ($value === true) {
if($value === false) $value = 'false'; $value = 'true';
} elseif ($value === false) {
$value = 'false';
}
$this->params[$key] = $value; $this->params[$key] = $value;
} }
......
...@@ -154,7 +154,9 @@ class Helper ...@@ -154,7 +154,9 @@ class Helper
case is_string($input) || is_numeric($input): case is_string($input) || is_numeric($input):
// if date/time string: convert to timestamp first // if date/time string: convert to timestamp first
if (is_string($input)) $input = strtotime($input); if (is_string($input)) {
$input = strtotime($input);
}
// now try converting the timestamp to a datetime instance, on failure return false // now try converting the timestamp to a datetime instance, on failure return false
try { try {
......
...@@ -77,7 +77,9 @@ abstract class RequestBuilder implements RequestBuilderInterface ...@@ -77,7 +77,9 @@ abstract class RequestBuilder implements RequestBuilderInterface
{ {
$params = ''; $params = '';
foreach ($localParams AS $paramName => $paramValue) { foreach ($localParams AS $paramName => $paramValue) {
if (empty($paramValue)) continue; if (empty($paramValue)) {
continue;
}
if (is_array($paramValue)) { if (is_array($paramValue)) {
$paramValue = implode($paramValue, ','); $paramValue = implode($paramValue, ',');
......
...@@ -209,9 +209,13 @@ class Customization extends Configurable ...@@ -209,9 +209,13 @@ class Customization extends Configurable
public function isValid() public function isValid()
{ {
$type = $this->getType(); $type = $this->getType();
if ($type !== self::TYPE_PARAM && $type !== self::TYPE_HEADER) return false; if ($type !== self::TYPE_PARAM && $type !== self::TYPE_HEADER) {
return false;
}
if (null == $this->getKey() || null == $this->getName() || null == $this->getValue()) return false; if (null == $this->getKey() || null == $this->getName() || null == $this->getValue()) {
return false;
}
return true; return true;
} }
......
...@@ -77,7 +77,9 @@ class WeightedRandomChoice ...@@ -77,7 +77,9 @@ class WeightedRandomChoice
{ {
$i = 0; $i = 0;
foreach ($choices AS $key => $weight) { foreach ($choices AS $key => $weight) {
if ($weight <=0) throw new Exception('Weight must be greater than zero'); if ($weight <=0) {
throw new Exception('Weight must be greater than zero');
}
$this->totalWeight += $weight; $this->totalWeight += $weight;
$this->lookup[$i] = $this->totalWeight; $this->lookup[$i] = $this->totalWeight;
...@@ -104,7 +106,9 @@ class WeightedRandomChoice ...@@ -104,7 +106,9 @@ class WeightedRandomChoice
$result = null; $result = null;
while (1) { while (1) {
$result = $this->values[$this->getKey()]; $result = $this->values[$this->getKey()];
if(!in_array($result, $excludes)) break; if (!in_array($result, $excludes)) {
break;
}
} }
return $result; return $result;
...@@ -122,7 +126,7 @@ class WeightedRandomChoice ...@@ -122,7 +126,7 @@ class WeightedRandomChoice
$low = 0; $low = 0;
while ( $low < $high ) { while ( $low < $high ) {
$probe = (int)(($high + $low) / 2); $probe = (int) (($high + $low) / 2);
if ($this->lookup[$probe] < $random) { if ($this->lookup[$probe] < $random) {
$low = $probe + 1; $low = $probe + 1;
} else if ($this->lookup[$probe] > $random) { } else if ($this->lookup[$probe] > $random) {
......
...@@ -90,9 +90,13 @@ class ParallelExecution extends Plugin ...@@ -90,9 +90,13 @@ class ParallelExecution extends Plugin
*/ */
public function addQuery($key, $query, $endpoint = null) public function addQuery($key, $query, $endpoint = null)
{ {
if (is_object($endpoint)) $endpoint = $endpoint->getKey(); if (is_object($endpoint)) {
$endpoint = $endpoint->getKey();
}
if($endpoint == null) $endpoint = $this->client->getEndpoint()->getKey(); if ($endpoint == null) {
$endpoint = $this->client->getEndpoint()->getKey();
}
$this->queries[$key] = array( $this->queries[$key] = array(
'query' => $query, 'query' => $query,
......
...@@ -146,7 +146,9 @@ class PrefetchIterator extends Plugin implements \Iterator, \Countable ...@@ -146,7 +146,9 @@ class PrefetchIterator extends Plugin implements \Iterator, \Countable
public function count() public function count()
{ {
// if no results are available yet, get them now // if no results are available yet, get them now
if (null == $this->result) $this->fetchNext(); if (null == $this->result) {
$this->fetchNext();
}
return $this->result->getNumFound(); return $this->result->getNumFound();
} }
...@@ -154,7 +156,7 @@ class PrefetchIterator extends Plugin implements \Iterator, \Countable ...@@ -154,7 +156,7 @@ class PrefetchIterator extends Plugin implements \Iterator, \Countable
/** /**
* Iterator implementation * Iterator implementation
*/ */
function rewind() public function rewind()
{ {
$this->position = 0; $this->position = 0;
...@@ -167,7 +169,7 @@ class PrefetchIterator extends Plugin implements \Iterator, \Countable ...@@ -167,7 +169,7 @@ class PrefetchIterator extends Plugin implements \Iterator, \Countable
/** /**
* Iterator implementation * Iterator implementation
*/ */
function current() public function current()
{ {
$adjustedIndex = $this->position % $this->options['prefetch']; $adjustedIndex = $this->position % $this->options['prefetch'];
return $this->documents[$adjustedIndex]; return $this->documents[$adjustedIndex];
...@@ -186,7 +188,7 @@ class PrefetchIterator extends Plugin implements \Iterator, \Countable ...@@ -186,7 +188,7 @@ class PrefetchIterator extends Plugin implements \Iterator, \Countable
/** /**
* Iterator implementation * Iterator implementation
*/ */
function next() public function next()
{ {
++$this->position; ++$this->position;
} }
...@@ -196,7 +198,7 @@ class PrefetchIterator extends Plugin implements \Iterator, \Countable ...@@ -196,7 +198,7 @@ class PrefetchIterator extends Plugin implements \Iterator, \Countable
* *
* @return boolean * @return boolean
*/ */
function valid() public function valid()
{ {
$adjustedIndex = $this->position % $this->options['prefetch']; $adjustedIndex = $this->position % $this->options['prefetch'];
......
...@@ -74,7 +74,7 @@ class ResponseParser extends SelectResponseParser ...@@ -74,7 +74,7 @@ class ResponseParser extends SelectResponseParser
$matchData = $data['match']['docs'][0]; $matchData = $data['match']['docs'][0];
$documentClass = $query->getOption('documentclass'); $documentClass = $query->getOption('documentclass');
$fields = (array)$matchData; $fields = (array) $matchData;
$parseResult['match'] = new $documentClass($fields); $parseResult['match'] = new $documentClass($fields);
} }
......
...@@ -75,7 +75,9 @@ abstract class Facet extends Configurable ...@@ -75,7 +75,9 @@ abstract class Facet extends Configurable
$this->setKey($value); $this->setKey($value);
break; break;
case 'exclude': case 'exclude':
if(!is_array($value)) $value = array($value); if (!is_array($value)) {
$value = array($value);
}
$this->setExcludes($value); $this->setExcludes($value);
unset($this->options['exclude']); unset($this->options['exclude']);
break; break;
......
...@@ -71,7 +71,9 @@ class MultiQuery extends Facet ...@@ -71,7 +71,9 @@ class MultiQuery extends Facet
foreach ($this->options AS $name => $value) { foreach ($this->options AS $name => $value) {
switch ($name) { switch ($name) {
case 'query': case 'query':
if(!is_array($value)) $value = array($value); if (!is_array($value)) {
$value = array($value);
}
$this->addQueries($value); $this->addQueries($value);
break; break;
} }
......
...@@ -229,7 +229,9 @@ class Grouping extends Component ...@@ -229,7 +229,9 @@ class Grouping extends Component
*/ */
public function addQueries($queries) public function addQueries($queries)
{ {
if(!is_array($queries)) $queries = array($queries); if (!is_array($queries)) {
$queries = array($queries);
}
$this->queries = array_merge($this->queries, $queries); $this->queries = array_merge($this->queries, $queries);
......
...@@ -72,7 +72,9 @@ class FilterQuery extends Configurable ...@@ -72,7 +72,9 @@ class FilterQuery extends Configurable
foreach ($this->options AS $name => $value) { foreach ($this->options AS $name => $value) {
switch ($name) { switch ($name) {
case 'tag': case 'tag':
if(!is_array($value)) $value = array($value); if (!is_array($value)) {
$value = array($value);
}
$this->addTags($value); $this->addTags($value);
break; break;
case 'key': case 'key':
......
...@@ -233,10 +233,10 @@ class Query extends BaseQuery ...@@ -233,10 +233,10 @@ class Query extends BaseQuery
$this->addFields($value); $this->addFields($value);
break; break;
case 'rows': case 'rows':
$this->setRows((int)$value); $this->setRows((int) $value);
break; break;
case 'start': case 'start':
$this->setStart((int)$value); $this->setStart((int) $value);
break; break;
case 'component': case 'component':
$this->createComponents($value); $this->createComponents($value);
......
...@@ -79,7 +79,9 @@ class FacetSet ...@@ -79,7 +79,9 @@ class FacetSet
throw new Exception('Unknown facet type'); throw new Exception('Unknown facet type');
} }
if($result !== null) $facets[$key] = $result; if ($result !== null) {
$facets[$key] = $result;
}
} }
return $this->createFacetSet($facets); return $this->createFacetSet($facets);
......
...@@ -62,7 +62,7 @@ class ResponseParser implements ResponseParserInterface ...@@ -62,7 +62,7 @@ class ResponseParser implements ResponseParserInterface
$documents = array(); $documents = array();
if (isset($data['response']['docs'])) { if (isset($data['response']['docs'])) {
foreach ($data['response']['docs'] AS $doc) { foreach ($data['response']['docs'] AS $doc) {
$fields = (array)$doc; $fields = (array) $doc;
$documents[] = new $documentClass($fields); $documents[] = new $documentClass($fields);
} }
} }
......
...@@ -359,8 +359,14 @@ class Query extends BaseQuery ...@@ -359,8 +359,14 @@ class Query extends BaseQuery
$commitWithin = null) $commitWithin = null)
{ {
$add = new Command\Add; $add = new Command\Add;
if (null !== $overwrite) $add->setOverwrite($overwrite);
if (null !== $commitWithin) $add->setCommitWithin($commitWithin); if (null !== $overwrite) {
$add->setOverwrite($overwrite);
}
if (null !== $commitWithin) {
$add->setCommitWithin($commitWithin);
}
$add->addDocuments($documents); $add->addDocuments($documents);
return $this->add(null, $add); return $this->add(null, $add);
...@@ -381,10 +387,18 @@ class Query extends BaseQuery ...@@ -381,10 +387,18 @@ class Query extends BaseQuery
$expungeDeletes = null) $expungeDeletes = null)
{ {
$commit = new Command\Commit(); $commit = new Command\Commit();
if (null !== $waitFlush) $commit->setWaitFlush($waitFlush);
if (null !== $waitSearcher) $commit->setWaitSearcher($waitSearcher); if (null !== $waitFlush) {
if (null !== $expungeDeletes) $commit->setWaitFlush($waitFlush);
}
if (null !== $waitSearcher) {
$commit->setWaitSearcher($waitSearcher);
}
if (null !== $expungeDeletes) {
$commit->setExpungeDeletes($expungeDeletes); $commit->setExpungeDeletes($expungeDeletes);
}
return $this->add(null, $commit); return $this->add(null, $commit);
} }
...@@ -404,9 +418,18 @@ class Query extends BaseQuery ...@@ -404,9 +418,18 @@ class Query extends BaseQuery
$maxSegments = null) $maxSegments = null)
{ {
$optimize = new Command\Optimize(); $optimize = new Command\Optimize();
if (null !== $waitFlush) $optimize->setWaitFlush($waitFlush);
if (null !== $waitSearcher) $optimize->setWaitSearcher($waitSearcher); if (null !== $waitFlush) {
if (null !== $maxSegments) $optimize->setMaxSegments($maxSegments); $optimize->setWaitFlush($waitFlush);
}
if (null !== $waitSearcher) {
$optimize->setWaitSearcher($waitSearcher);
}
if (null !== $maxSegments) {
$optimize->setMaxSegments($maxSegments);
}
return $this->add(null, $optimize); return $this->add(null, $optimize);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment