From c40d4114ec14f468ea563de3c1d9153c955d6b30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Tue, 3 Oct 2023 09:38:31 +0200 Subject: [PATCH] Fixed issues reported by phpstan --- src/bundle/ApiLoader/BoostFactorProviderFactory.php | 6 ++++++ src/bundle/ApiLoader/IndexingDepthProviderFactory.php | 6 ++++++ .../Common/CriterionVisitor/ContentTypeIdentifierIn.php | 2 +- src/lib/Query/Content/CriterionVisitor/Ancestor.php | 2 +- src/lib/Query/Location/CriterionVisitor/Ancestor.php | 2 +- 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/bundle/ApiLoader/BoostFactorProviderFactory.php b/src/bundle/ApiLoader/BoostFactorProviderFactory.php index 7cf24a26..5b3cc283 100644 --- a/src/bundle/ApiLoader/BoostFactorProviderFactory.php +++ b/src/bundle/ApiLoader/BoostFactorProviderFactory.php @@ -7,6 +7,8 @@ namespace Ibexa\Bundle\Solr\ApiLoader; use Ibexa\Bundle\Core\ApiLoader\RepositoryConfigurationProvider; +use Ibexa\Solr\FieldMapper\BoostFactorProvider; +use LogicException; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerAwareTrait; @@ -48,6 +50,10 @@ public function __construct( public function buildService() { + if ($this->container === null) { + throw new LogicException(sprintf('Unable to build %s due to missing container reference', BoostFactorProvider::class)); + } + $repositoryConfig = $this->repositoryConfigurationProvider->getRepositoryConfig(); $connection = $this->defaultConnection; diff --git a/src/bundle/ApiLoader/IndexingDepthProviderFactory.php b/src/bundle/ApiLoader/IndexingDepthProviderFactory.php index 8f46fe3b..c25017bf 100644 --- a/src/bundle/ApiLoader/IndexingDepthProviderFactory.php +++ b/src/bundle/ApiLoader/IndexingDepthProviderFactory.php @@ -9,6 +9,8 @@ namespace Ibexa\Bundle\Solr\ApiLoader; use Ibexa\Bundle\Core\ApiLoader\RepositoryConfigurationProvider; +use Ibexa\Solr\FieldMapper\IndexingDepthProvider; +use LogicException; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerAwareTrait; @@ -43,6 +45,10 @@ public function __construct( public function buildService() { + if ($this->container === null) { + throw new LogicException(sprintf('Unable to build %s due to missing container reference', IndexingDepthProvider::class)); + } + $repositoryConfig = $this->repositoryConfigurationProvider->getRepositoryConfig(); $connection = $this->defaultConnection; diff --git a/src/lib/Query/Common/CriterionVisitor/ContentTypeIdentifierIn.php b/src/lib/Query/Common/CriterionVisitor/ContentTypeIdentifierIn.php index f29df011..ccf4b805 100644 --- a/src/lib/Query/Common/CriterionVisitor/ContentTypeIdentifierIn.php +++ b/src/lib/Query/Common/CriterionVisitor/ContentTypeIdentifierIn.php @@ -70,7 +70,7 @@ public function visit(Criterion $criterion, CriterionVisitor $subVisitor = null) foreach ($criterion->value as $identifier) { try { - $validIds[] = $contentTypeHandler->loadByIdentifier($identifier)->id; + $validIds[] = $contentTypeHandler->loadByIdentifier((string) $identifier)->id; } catch (NotFoundException $e) { // Filter out non-existing content types, but track for code below $invalidIdentifiers[] = $identifier; diff --git a/src/lib/Query/Content/CriterionVisitor/Ancestor.php b/src/lib/Query/Content/CriterionVisitor/Ancestor.php index eaab4210..09442036 100644 --- a/src/lib/Query/Content/CriterionVisitor/Ancestor.php +++ b/src/lib/Query/Content/CriterionVisitor/Ancestor.php @@ -36,7 +36,7 @@ public function visit(Criterion $criterion, CriterionVisitor $subVisitor = null) { $idSet = []; foreach ($criterion->value as $value) { - foreach (explode('/', trim($value, '/')) as $id) { + foreach (explode('/', trim((string)$value, '/')) as $id) { $idSet[$id] = true; } } diff --git a/src/lib/Query/Location/CriterionVisitor/Ancestor.php b/src/lib/Query/Location/CriterionVisitor/Ancestor.php index b7aafb45..86f1be4e 100644 --- a/src/lib/Query/Location/CriterionVisitor/Ancestor.php +++ b/src/lib/Query/Location/CriterionVisitor/Ancestor.php @@ -36,7 +36,7 @@ public function visit(Criterion $criterion, CriterionVisitor $subVisitor = null) { $idSet = []; foreach ($criterion->value as $value) { - foreach (explode('/', trim($value, '/')) as $id) { + foreach (explode('/', trim((string)$value, '/')) as $id) { $idSet[$id] = true; } }