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
$this->endpoints[$key] = $endpoint;
// 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;
......@@ -300,9 +302,11 @@ class Client extends Configurable
*/
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');
}
......@@ -497,7 +501,9 @@ class Client extends Configurable
// support both "key=>value" and "(no-key) => array(key=>x,query=>y)" formats
if (is_array($class)) {
if (isset($class['type'])) $type = $class['type'];
if (isset($class['type'])) {
$type = $class['type'];
}
$class = $class['query'];
}
......@@ -555,7 +561,9 @@ class Client extends Configurable
{
foreach ($plugins as $key => $plugin) {
if (!isset($plugin['key'])) $plugin['key'] = $key;
if (!isset($plugin['key'])) {
$plugin['key'] = $key;
}
$this->registerPlugin(
$plugin['key'],
......@@ -678,7 +686,9 @@ class Client extends Configurable
public function createRequest(QueryInterface $query)
{
$pluginResult = $this->callPlugins('preCreateRequest', array($query), true);
if($pluginResult !== null) return $pluginResult;
if($pluginResult !== null) {
return $pluginResult;
}
$requestBuilder = $query->getRequestBuilder();
if (!$requestBuilder || !($requestBuilder instanceof RequestBuilderInterface)) {
......@@ -702,7 +712,9 @@ class Client extends Configurable
public function createResult(QueryInterface $query, $response)
{
$pluginResult = $this->callPlugins('preCreateResult', array($query, $response), true);
if($pluginResult !== null) return $pluginResult;
if ($pluginResult !== null) {
return $pluginResult;
}
$resultClass = $query->getResultClass();
$result = new $resultClass($this, $query, $response);
......@@ -726,7 +738,9 @@ class Client extends Configurable
public function execute(QueryInterface $query, $endpoint = null)
{
$pluginResult = $this->callPlugins('preExecute', array($query), true);
if($pluginResult !== null) return $pluginResult;
if ($pluginResult !== null) {
return $pluginResult;
}
$request = $this->createRequest($query);
$response = $this->executeRequest($request, $endpoint);
......@@ -920,7 +934,9 @@ class Client extends Configurable
$type = strtolower($type);
$pluginResult = $this->callPlugins('preCreateQuery', array($type, $options), true);
if($pluginResult !== null) return $pluginResult;
if($pluginResult !== null) {
return $pluginResult;
}
if (!isset($this->queryTypes[$type])) {
throw new Exception('Unknown querytype: '. $type);
......
......@@ -151,7 +151,9 @@ class Endpoint extends Configurable
*/
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);
}
......
......@@ -219,8 +219,11 @@ class Request extends Configurable
$this->params[$key][] = $value;
} else {
// not all solr handlers support 0/1 as boolean values...
if($value === true) $value = 'true';
if($value === false) $value = 'false';
if ($value === true) {
$value = 'true';
} elseif ($value === false) {
$value = 'false';
}
$this->params[$key] = $value;
}
......
......@@ -154,7 +154,9 @@ class Helper
case is_string($input) || is_numeric($input):
// 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
try {
......
......@@ -77,7 +77,9 @@ abstract class RequestBuilder implements RequestBuilderInterface
{
$params = '';
foreach ($localParams AS $paramName => $paramValue) {
if (empty($paramValue)) continue;
if (empty($paramValue)) {
continue;
}
if (is_array($paramValue)) {
$paramValue = implode($paramValue, ',');
......
......@@ -209,9 +209,13 @@ class Customization extends Configurable
public function isValid()
{
$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;
}
......
......@@ -77,7 +77,9 @@ class WeightedRandomChoice
{
$i = 0;
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->lookup[$i] = $this->totalWeight;
......@@ -104,7 +106,9 @@ class WeightedRandomChoice
$result = null;
while (1) {
$result = $this->values[$this->getKey()];
if(!in_array($result, $excludes)) break;
if (!in_array($result, $excludes)) {
break;
}
}
return $result;
......@@ -122,7 +126,7 @@ class WeightedRandomChoice
$low = 0;
while ( $low < $high ) {
$probe = (int)(($high + $low) / 2);
$probe = (int) (($high + $low) / 2);
if ($this->lookup[$probe] < $random) {
$low = $probe + 1;
} else if ($this->lookup[$probe] > $random) {
......
......@@ -90,9 +90,13 @@ class ParallelExecution extends Plugin
*/
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(
'query' => $query,
......
......@@ -146,7 +146,9 @@ class PrefetchIterator extends Plugin implements \Iterator, \Countable
public function count()
{
// 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();
}
......@@ -154,7 +156,7 @@ class PrefetchIterator extends Plugin implements \Iterator, \Countable
/**
* Iterator implementation
*/
function rewind()
public function rewind()
{
$this->position = 0;
......@@ -167,7 +169,7 @@ class PrefetchIterator extends Plugin implements \Iterator, \Countable
/**
* Iterator implementation
*/
function current()
public function current()
{
$adjustedIndex = $this->position % $this->options['prefetch'];
return $this->documents[$adjustedIndex];
......@@ -186,7 +188,7 @@ class PrefetchIterator extends Plugin implements \Iterator, \Countable
/**
* Iterator implementation
*/
function next()
public function next()
{
++$this->position;
}
......@@ -196,7 +198,7 @@ class PrefetchIterator extends Plugin implements \Iterator, \Countable
*
* @return boolean
*/
function valid()
public function valid()
{
$adjustedIndex = $this->position % $this->options['prefetch'];
......
......@@ -74,7 +74,7 @@ class ResponseParser extends SelectResponseParser
$matchData = $data['match']['docs'][0];
$documentClass = $query->getOption('documentclass');
$fields = (array)$matchData;
$fields = (array) $matchData;
$parseResult['match'] = new $documentClass($fields);
}
......
......@@ -75,7 +75,9 @@ abstract class Facet extends Configurable
$this->setKey($value);
break;
case 'exclude':
if(!is_array($value)) $value = array($value);
if (!is_array($value)) {
$value = array($value);
}
$this->setExcludes($value);
unset($this->options['exclude']);
break;
......
......@@ -71,7 +71,9 @@ class MultiQuery extends Facet
foreach ($this->options AS $name => $value) {
switch ($name) {
case 'query':
if(!is_array($value)) $value = array($value);
if (!is_array($value)) {
$value = array($value);
}
$this->addQueries($value);
break;
}
......
......@@ -229,7 +229,9 @@ class Grouping extends Component
*/
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);
......
......@@ -72,7 +72,9 @@ class FilterQuery extends Configurable
foreach ($this->options AS $name => $value) {
switch ($name) {
case 'tag':
if(!is_array($value)) $value = array($value);
if (!is_array($value)) {
$value = array($value);
}
$this->addTags($value);
break;
case 'key':
......
......@@ -233,10 +233,10 @@ class Query extends BaseQuery
$this->addFields($value);
break;
case 'rows':
$this->setRows((int)$value);
$this->setRows((int) $value);
break;
case 'start':
$this->setStart((int)$value);
$this->setStart((int) $value);
break;
case 'component':
$this->createComponents($value);
......
......@@ -79,7 +79,9 @@ class FacetSet
throw new Exception('Unknown facet type');
}
if($result !== null) $facets[$key] = $result;
if ($result !== null) {
$facets[$key] = $result;
}
}
return $this->createFacetSet($facets);
......
......@@ -62,7 +62,7 @@ class ResponseParser implements ResponseParserInterface
$documents = array();
if (isset($data['response']['docs'])) {
foreach ($data['response']['docs'] AS $doc) {
$fields = (array)$doc;
$fields = (array) $doc;
$documents[] = new $documentClass($fields);
}
}
......
......@@ -359,8 +359,14 @@ class Query extends BaseQuery
$commitWithin = null)
{
$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);
return $this->add(null, $add);
......@@ -381,10 +387,18 @@ class Query extends BaseQuery
$expungeDeletes = null)
{
$commit = new Command\Commit();
if (null !== $waitFlush) $commit->setWaitFlush($waitFlush);
if (null !== $waitSearcher) $commit->setWaitSearcher($waitSearcher);
if (null !== $expungeDeletes)
if (null !== $waitFlush) {
$commit->setWaitFlush($waitFlush);
}
if (null !== $waitSearcher) {
$commit->setWaitSearcher($waitSearcher);
}
if (null !== $expungeDeletes) {
$commit->setExpungeDeletes($expungeDeletes);
}
return $this->add(null, $commit);
}
......@@ -404,9 +418,18 @@ class Query extends BaseQuery
$maxSegments = null)
{
$optimize = new Command\Optimize();
if (null !== $waitFlush) $optimize->setWaitFlush($waitFlush);
if (null !== $waitSearcher) $optimize->setWaitSearcher($waitSearcher);
if (null !== $maxSegments) $optimize->setMaxSegments($maxSegments);
if (null !== $waitFlush) {
$optimize->setWaitFlush($waitFlush);
}
if (null !== $waitSearcher) {
$optimize->setWaitSearcher($waitSearcher);
}
if (null !== $maxSegments) {
$optimize->setMaxSegments($maxSegments);
}
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