From 74e7408a94ae35070f15866ff45c1119df927559 Mon Sep 17 00:00:00 2001 From: David Maus <dmaus@dmaus.name> Date: Mon, 25 Nov 2019 20:38:56 +0100 Subject: [PATCH] Fix type errors --- src/HAB/Solr/Command/QueryBuilder.php | 4 ++-- src/HAB/Solr/Command/Search.php | 2 +- src/HAB/Solr/Facet/AbstractFacetAdapter.php | 10 +++++----- src/HAB/Solr/Facet/DefaultFacetAdapter.php | 13 ++----------- src/HAB/Solr/Facet/FacetCollection.php | 2 +- src/HAB/Solr/Facet/Impl/FieldFacet.php | 4 ++-- .../Solr/Facet/LabelFactory/RegExpLabelFactory.php | 4 ++-- .../Solr/Facet/StateFilter/DefaultStateFilter.php | 2 +- .../Solr/Facet/Value/Container/FacetValueList.php | 6 +++--- .../Solr/Facet/Value/Container/FacetValueTree.php | 8 ++++---- .../Facet/Value/Container/FacetValueTreeNode.php | 10 +++++----- src/HAB/Solr/Facet/Value/FacetValue.php | 2 +- .../ValueMapper/RequestValueArrayMapMapper.php | 4 ++-- .../ValueMapper/RequestValueMapperInterface.php | 6 +++--- .../Facet/ValueMapper/RequestValuePrefixMapper.php | 4 ++-- src/HAB/Solr/ParamBag.php | 4 ++-- src/HAB/Solr/Response/Json/Facets.php | 6 +++--- src/HAB/Solr/Response/Json/QuerySuggestion.php | 10 +++++----- 18 files changed, 46 insertions(+), 55 deletions(-) diff --git a/src/HAB/Solr/Command/QueryBuilder.php b/src/HAB/Solr/Command/QueryBuilder.php index f76d87f..2c9e155 100644 --- a/src/HAB/Solr/Command/QueryBuilder.php +++ b/src/HAB/Solr/Command/QueryBuilder.php @@ -37,7 +37,7 @@ class QueryBuilder implements QueryBuilderInterface /** * Return Solr query parameters. * - * @param array|\ArrayAccess $query + * @param iterable $query * @return ParamBag */ public function buildQuery ($query) @@ -48,4 +48,4 @@ class QueryBuilder implements QueryBuilderInterface } return $params; } -} \ No newline at end of file +} diff --git a/src/HAB/Solr/Command/Search.php b/src/HAB/Solr/Command/Search.php index 5bd9c1c..37303ee 100644 --- a/src/HAB/Solr/Command/Search.php +++ b/src/HAB/Solr/Command/Search.php @@ -119,7 +119,7 @@ class Search implements CommandInterface public function getQuery () { - if (is_null($this->query)) { + if ($this->query === null) { $this->setQuery(new ArrayObject()); } return $this->query; diff --git a/src/HAB/Solr/Facet/AbstractFacetAdapter.php b/src/HAB/Solr/Facet/AbstractFacetAdapter.php index 4a4ccb6..e0606e8 100644 --- a/src/HAB/Solr/Facet/AbstractFacetAdapter.php +++ b/src/HAB/Solr/Facet/AbstractFacetAdapter.php @@ -140,10 +140,10 @@ abstract class AbstractFacetAdapter implements FacetAdapterInterface */ public function getFacetValueContainer () { - if (!$this->container) { + if ($this->container === null) { $this->setFacetValueContainer(new Value\Container\FacetValueList()); } - if ($this->sort) { + if ($this->sort !== null) { call_user_func($this->sort, $this->container); } return $this->container; @@ -165,7 +165,7 @@ abstract class AbstractFacetAdapter implements FacetAdapterInterface */ public function getRequestValueMapper () { - if (!$this->mapper) { + if ($this->mapper === null) { $this->setRequestValueMapper(new ValueMapper\RequestValueIdentityMapper()); } return $this->mapper; @@ -189,7 +189,7 @@ abstract class AbstractFacetAdapter implements FacetAdapterInterface public function setComponentState (array $state) { if (array_key_exists('f', $state)) { - $params = $state->get('f'); + $params = $state['f']; if ($params && is_array($params) && isset($params[$this->getName()])) { $this->setFilterValues($params[$this->getName()]); } @@ -200,7 +200,7 @@ abstract class AbstractFacetAdapter implements FacetAdapterInterface public function getGlobalComponentState () { if ($this->state) { - return $this->state->all(); + return $this->state; } return array(); } diff --git a/src/HAB/Solr/Facet/DefaultFacetAdapter.php b/src/HAB/Solr/Facet/DefaultFacetAdapter.php index 01c3ac3..3d85d0e 100644 --- a/src/HAB/Solr/Facet/DefaultFacetAdapter.php +++ b/src/HAB/Solr/Facet/DefaultFacetAdapter.php @@ -85,20 +85,11 @@ class DefaultFacetAdapter extends AbstractFacetAdapter return $this->getRequestValueMapper()->mapToRequest($this->facet->getSelected()); } - /** - * {@inheritDoc} - */ - public function getSearchParameters () - { - return $this->facet->getSearchParameters(); - } - /** * {@inheritDoc} */ public function setRecordCollection (RecordCollection $response) { - $this->facet->setRecordCollection($response); $container = $this->getFacetValueContainer(); $factory = $this->getFacetValueLabelFactory(); $selected = $this->facet->getSelected(); @@ -133,7 +124,7 @@ class DefaultFacetAdapter extends AbstractFacetAdapter */ public function getFacetValueLabelFactory () { - if (!$this->labelFactory) { + if ($this->labelFactory === null) { $this->setFacetValueLabelFactory(new LabelFactory\DefaultLabelFactory()); } return $this->labelFactory; @@ -149,4 +140,4 @@ class DefaultFacetAdapter extends AbstractFacetAdapter { $this->labelFactory = $factory; } -} \ No newline at end of file +} diff --git a/src/HAB/Solr/Facet/FacetCollection.php b/src/HAB/Solr/Facet/FacetCollection.php index 3f55fd5..53bf6bd 100644 --- a/src/HAB/Solr/Facet/FacetCollection.php +++ b/src/HAB/Solr/Facet/FacetCollection.php @@ -116,7 +116,7 @@ class FacetCollection implements Countable, IteratorAggregate, ParameterProvider */ public function getComponentStateFilter () { - if (!$this->filter) { + if ($this->filter === null) { $this->setComponentStateFilter(new StateFilter\DefaultStateFilter()); } return $this->filter; diff --git a/src/HAB/Solr/Facet/Impl/FieldFacet.php b/src/HAB/Solr/Facet/Impl/FieldFacet.php index 4d81202..7292ccd 100644 --- a/src/HAB/Solr/Facet/Impl/FieldFacet.php +++ b/src/HAB/Solr/Facet/Impl/FieldFacet.php @@ -64,7 +64,7 @@ class FieldFacet implements FacetImplInterface /** * Filter query tag, if any. * - * @var string + * @var string|null */ private $fqTag; @@ -356,7 +356,7 @@ class FieldFacet implements FacetImplInterface */ public function __clone () { - if ($this->localParams) { + if ($this->localParams !== null) { $this->localParams = clone($this->localParams); } $this->fqTag = null; diff --git a/src/HAB/Solr/Facet/LabelFactory/RegExpLabelFactory.php b/src/HAB/Solr/Facet/LabelFactory/RegExpLabelFactory.php index 7cd9faf..50adfbd 100644 --- a/src/HAB/Solr/Facet/LabelFactory/RegExpLabelFactory.php +++ b/src/HAB/Solr/Facet/LabelFactory/RegExpLabelFactory.php @@ -65,8 +65,8 @@ class RegExpLabelFactory implements LabelFactoryInterface public function createLabel ($value) { if (preg_match($this->pattern, $value)) { - return preg_replace($this->pattern, $this->template, $value); + return (string)preg_replace($this->pattern, $this->template, $value); } return $value; } -} \ No newline at end of file +} diff --git a/src/HAB/Solr/Facet/StateFilter/DefaultStateFilter.php b/src/HAB/Solr/Facet/StateFilter/DefaultStateFilter.php index 9419b1c..ec121f6 100644 --- a/src/HAB/Solr/Facet/StateFilter/DefaultStateFilter.php +++ b/src/HAB/Solr/Facet/StateFilter/DefaultStateFilter.php @@ -41,6 +41,6 @@ class DefaultStateFilter implements StateFilterInterface */ public function filter (array $state) { - return clone($state); + return $state; } } diff --git a/src/HAB/Solr/Facet/Value/Container/FacetValueList.php b/src/HAB/Solr/Facet/Value/Container/FacetValueList.php index f5aefba..2671820 100644 --- a/src/HAB/Solr/Facet/Value/Container/FacetValueList.php +++ b/src/HAB/Solr/Facet/Value/Container/FacetValueList.php @@ -103,7 +103,7 @@ class FacetValueList implements ContainerInterface */ public function sortByLabel ($reverse = false) { - usort($this->values, array('HAB Solr\Search\Facet\Value\FacetValue', 'compareByLabel')); + usort($this->values, array(FacetValue::class, 'compareByLabel')); if ($reverse) { $this->values = array_reverse($this->values); } @@ -114,7 +114,7 @@ class FacetValueList implements ContainerInterface */ public function sortByCount ($reverse = false) { - usort($this->values, array('HAB Solr\Search\Facet\Value\FacetValue', 'compareByCount')); + usort($this->values, array(FacetValue::class, 'compareByCount')); if ($reverse) { $this->values = array_reverse($this->values); } @@ -127,4 +127,4 @@ class FacetValueList implements ContainerInterface { return count($this->values); } -} \ No newline at end of file +} diff --git a/src/HAB/Solr/Facet/Value/Container/FacetValueTree.php b/src/HAB/Solr/Facet/Value/Container/FacetValueTree.php index cd627d6..fbfb892 100644 --- a/src/HAB/Solr/Facet/Value/Container/FacetValueTree.php +++ b/src/HAB/Solr/Facet/Value/Container/FacetValueTree.php @@ -69,13 +69,13 @@ class FacetValueTree implements ContainerInterface /** * Constructor. * - * @param FacetValueTreePathFactory $pathFactory + * @param PathFactory\PathFactoryInterface $pathFactory * @return void */ public function __construct (PathFactory\PathFactoryInterface $pathFactory) { $this->pathFactory = $pathFactory; - $this->rootNode = new FacetValueTreeNode(uniqid(true)); + $this->rootNode = new FacetValueTreeNode(uniqid('node', true)); $this->values = array(); } @@ -152,7 +152,7 @@ class FacetValueTree implements ContainerInterface public function sortByLabel ($reverse = false) { $this->rootNode->sortByLabel($reverse); - $sortfunc = array('HAB Solr\Search\Facet\Value\FacetValue', 'compareByLabel'); + $sortfunc = array(FacetValue::class, 'compareByLabel'); usort($this->values, $sortfunc); if ($reverse) { $this->values = array_reverse($this->values); @@ -164,7 +164,7 @@ class FacetValueTree implements ContainerInterface */ public function sortByCount ($reverse = false) { - $sortfunc = array('HAB Solr\Search\Facet\Value\FacetValue', 'compareByCount'); + $sortfunc = array(FacetValue::class, 'compareByCount'); $this->sortByFunction($sortfunc, $reverse); } diff --git a/src/HAB/Solr/Facet/Value/Container/FacetValueTreeNode.php b/src/HAB/Solr/Facet/Value/Container/FacetValueTreeNode.php index 1acca45..ea147d8 100644 --- a/src/HAB/Solr/Facet/Value/Container/FacetValueTreeNode.php +++ b/src/HAB/Solr/Facet/Value/Container/FacetValueTreeNode.php @@ -82,7 +82,7 @@ class FacetValueTreeNode implements RecursiveIterator public static function getCollator () { if (self::$collator === null) { - self::$collator = new Collator(null); + self::$collator = new Collator(''); } return self::$collator; } @@ -199,7 +199,7 @@ class FacetValueTreeNode implements RecursiveIterator /** * Return node value. * - * @return FacetValue|null + * @return FacetValue */ public function getValue () { @@ -213,7 +213,7 @@ class FacetValueTreeNode implements RecursiveIterator */ public function hasValue () { - return !!$this->value; + return $this->value !== null; } /** @@ -292,7 +292,7 @@ class FacetValueTreeNode implements RecursiveIterator foreach ($this->childNodes as $node) { $node->sortByLabel($reverse); } - usort($this->childNodes, 'self::compareByLabel'); + usort($this->childNodes, array(FacetValueTreeNode::class, 'compareByLabel')); if ($reverse) { $this->childNodes = array_reverse($this->childNodes); } @@ -390,4 +390,4 @@ class FacetValueTreeNode implements RecursiveIterator return $this->current(); } -} \ No newline at end of file +} diff --git a/src/HAB/Solr/Facet/Value/FacetValue.php b/src/HAB/Solr/Facet/Value/FacetValue.php index 3f6bd1f..226ffc4 100644 --- a/src/HAB/Solr/Facet/Value/FacetValue.php +++ b/src/HAB/Solr/Facet/Value/FacetValue.php @@ -92,7 +92,7 @@ class FacetValue public static function getCollator () { if (self::$collator === null) { - self::$collator = new Collator(null); + self::$collator = new Collator(''); } return self::$collator; } diff --git a/src/HAB/Solr/Facet/ValueMapper/RequestValueArrayMapMapper.php b/src/HAB/Solr/Facet/ValueMapper/RequestValueArrayMapMapper.php index bae9b74..25d982e 100644 --- a/src/HAB/Solr/Facet/ValueMapper/RequestValueArrayMapMapper.php +++ b/src/HAB/Solr/Facet/ValueMapper/RequestValueArrayMapMapper.php @@ -122,9 +122,9 @@ class RequestValueArrayMapMapper implements RequestValueMapperInterface private function lookupRequestValue ($facetValue) { $key = array_search($facetValue, $this->map); - if ($key !== false) { + if (is_string($key)) { return $key; } return null; } -} \ No newline at end of file +} diff --git a/src/HAB/Solr/Facet/ValueMapper/RequestValueMapperInterface.php b/src/HAB/Solr/Facet/ValueMapper/RequestValueMapperInterface.php index 527eb1d..4157ba0 100644 --- a/src/HAB/Solr/Facet/ValueMapper/RequestValueMapperInterface.php +++ b/src/HAB/Solr/Facet/ValueMapper/RequestValueMapperInterface.php @@ -53,7 +53,7 @@ interface RequestValueMapperInterface * Map a single value from request to internal representation. * * @param string $value - * @return string + * @return string|null */ public function mapFromRequestSingleValue ($value); @@ -61,7 +61,7 @@ interface RequestValueMapperInterface * Map a single value from internal representation to request. * * @param string $value - * @return string + * @return string|null */ public function mapToRequestSingleValue ($value); -} \ No newline at end of file +} diff --git a/src/HAB/Solr/Facet/ValueMapper/RequestValuePrefixMapper.php b/src/HAB/Solr/Facet/ValueMapper/RequestValuePrefixMapper.php index 071cf6b..19f35dd 100644 --- a/src/HAB/Solr/Facet/ValueMapper/RequestValuePrefixMapper.php +++ b/src/HAB/Solr/Facet/ValueMapper/RequestValuePrefixMapper.php @@ -66,7 +66,7 @@ class RequestValuePrefixMapper implements RequestValueMapperInterface if (is_array($values)) { return array_map(array($this, 'addPrefix'), $values); } - return $this->addPrefix($values); + return (array)$this->addPrefix($values); } /** @@ -117,4 +117,4 @@ class RequestValuePrefixMapper implements RequestValueMapperInterface { return $this->prefix . $value; } -} \ No newline at end of file +} diff --git a/src/HAB/Solr/ParamBag.php b/src/HAB/Solr/ParamBag.php index db4e1e9..2cd6a24 100644 --- a/src/HAB/Solr/ParamBag.php +++ b/src/HAB/Solr/ParamBag.php @@ -95,7 +95,7 @@ class ParamBag * Set a parameter. * * @param string $name Parameter name - * @param string $value Parameter value + * @param mixed $value Parameter value * * @return void */ @@ -229,4 +229,4 @@ class ParamBag } return $request; } -} \ No newline at end of file +} diff --git a/src/HAB/Solr/Response/Json/Facets.php b/src/HAB/Solr/Response/Json/Facets.php index 0a46a50..38007d9 100644 --- a/src/HAB/Solr/Response/Json/Facets.php +++ b/src/HAB/Solr/Response/Json/Facets.php @@ -84,7 +84,7 @@ class Facets */ public function getFieldFacets() { - if (!$this->fields) { + if ($this->fields === null) { $this->fields = new ArrayObject(); if (isset($this->facets['facet_fields'])) { foreach ($this->facets['facet_fields'] as $name => $info) { @@ -102,7 +102,7 @@ class Facets */ public function getQueryFacets() { - if (!$this->queries) { + if ($this->queries === null) { $this->queries = new ArrayObject(); if (isset($this->facets['facet_queries'])) { $this->queries->exchangeArray($this->facets['facet_queries']); @@ -111,4 +111,4 @@ class Facets return $this->queries; } -} \ No newline at end of file +} diff --git a/src/HAB/Solr/Response/Json/QuerySuggestion.php b/src/HAB/Solr/Response/Json/QuerySuggestion.php index 78d4c4c..64e545a 100644 --- a/src/HAB/Solr/Response/Json/QuerySuggestion.php +++ b/src/HAB/Solr/Response/Json/QuerySuggestion.php @@ -50,7 +50,7 @@ class QuerySuggestion /** * Number of records matching the query. * - * @var integer|false + * @var integer|null */ private $hits; @@ -58,11 +58,11 @@ class QuerySuggestion * Constructor. * * @param string $query - * @param integer $hitcount + * @param integer $hits * * @return void */ - public function __construct ($query, $hits = false) + public function __construct ($query, $hits = null) { $this->query = $query; $this->hits = $hits; @@ -81,10 +81,10 @@ class QuerySuggestion /** * Return number of matching records. * - * @return integer + * @return integer|null */ public function getHits () { return $this->hits; } -} \ No newline at end of file +} -- GitLab