From d4e89d85b3026628ae1e2190c204a6bf75f28f91 Mon Sep 17 00:00:00 2001 From: Dawid Parafinski Date: Thu, 28 Nov 2024 09:38:44 +0100 Subject: [PATCH] Added typehint to Query::query --- phpstan-baseline.neon | 14 ++------------ src/contracts/Repository/Values/Content/Query.php | 4 +--- src/lib/Repository/SearchService.php | 2 +- .../Core/Repository/SearchServiceLocationTest.php | 1 + .../Core/Repository/SearchServiceTest.php | 1 + 5 files changed, 6 insertions(+), 16 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index dd62882ae0..d4cdf29381 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -21532,7 +21532,7 @@ parameters: - message: "#^Cannot access offset 0 on array\\\\|bool\\|float\\|int\\|string\\.$#" - count: 2 + count: 1 path: src/lib/Search/Legacy/Content/Location/Gateway/CriterionHandler/Location/IsMainLocation.php - @@ -21592,7 +21592,7 @@ parameters: - message: "#^Cannot access offset 0 on array\\\\|bool\\|float\\|int\\|string\\.$#" - count: 2 + count: 1 path: src/lib/Search/Legacy/Content/Location/Gateway/CriterionHandler/Visibility.php - @@ -46120,11 +46120,6 @@ parameters: count: 1 path: tests/lib/Pagination/ContentSearchHitAdapterTest.php - - - message: "#^Property Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Query\\:\\:\\$query \\(Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Query\\\\Criterion\\) does not accept Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Query\\\\CriterionInterface&PHPUnit\\\\Framework\\\\MockObject\\\\MockObject\\.$#" - count: 1 - path: tests/lib/Pagination/ContentSearchHitAdapterTest.php - - message: "#^Method Ibexa\\\\Tests\\\\Core\\\\Pagination\\\\LocationSearchAdapterTest\\:\\:getAdapter\\(\\) has parameter \\$languageFilter with no value type specified in iterable type array\\.$#" count: 1 @@ -46155,11 +46150,6 @@ parameters: count: 1 path: tests/lib/Pagination/LocationSearchHitAdapterTest.php - - - message: "#^Property Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Query\\:\\:\\$query \\(Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Query\\\\Criterion\\) does not accept Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Query\\\\CriterionInterface&PHPUnit\\\\Framework\\\\MockObject\\\\MockObject\\.$#" - count: 1 - path: tests/lib/Pagination/LocationSearchHitAdapterTest.php - - message: "#^Method Ibexa\\\\Tests\\\\Core\\\\Persistence\\\\Cache\\\\AbstractBaseHandlerTest\\:\\:getCacheItem\\(\\) has parameter \\$key with no type specified\\.$#" count: 1 diff --git a/src/contracts/Repository/Values/Content/Query.php b/src/contracts/Repository/Values/Content/Query.php index 243dd7c892..689d5baee3 100644 --- a/src/contracts/Repository/Values/Content/Query.php +++ b/src/contracts/Repository/Values/Content/Query.php @@ -44,10 +44,8 @@ class Query extends ValueObject * * Can contain multiple criterion, as items of a logical one (by default * AND). Defaults to MatchAll. - * - * @var \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion */ - public $query; + public ?CriterionInterface $query = null; /** * Query sorting clauses. diff --git a/src/lib/Repository/SearchService.php b/src/lib/Repository/SearchService.php index cae77c5685..76555a3929 100644 --- a/src/lib/Repository/SearchService.php +++ b/src/lib/Repository/SearchService.php @@ -169,7 +169,7 @@ protected function internalFindContentInfo(Query $query, array $languageFilter = $query = clone $query; $query->filter = $query->filter ?: new Criterion\MatchAll(); - $this->validateContentCriteria([$query->query], '$query'); + $this->validateContentCriteria($query->query ? [$query->query] : [], '$query'); $this->validateContentCriteria([$query->filter], '$query'); $this->validateContentSortClauses($query); diff --git a/tests/integration/Core/Repository/SearchServiceLocationTest.php b/tests/integration/Core/Repository/SearchServiceLocationTest.php index 4974ea32d9..9381c5fc10 100644 --- a/tests/integration/Core/Repository/SearchServiceLocationTest.php +++ b/tests/integration/Core/Repository/SearchServiceLocationTest.php @@ -524,6 +524,7 @@ public function testQueryModifiedField() 'sortClauses' => [new SortClause\ContentId()], ] ); + self::assertInstanceOf(Criterion::class, $query->query); $query->query->setCustomField('user', 'first_name', 'custom_field'); $this->assertQueryFixture( diff --git a/tests/integration/Core/Repository/SearchServiceTest.php b/tests/integration/Core/Repository/SearchServiceTest.php index 67fe34177a..2687555d3d 100644 --- a/tests/integration/Core/Repository/SearchServiceTest.php +++ b/tests/integration/Core/Repository/SearchServiceTest.php @@ -2930,6 +2930,7 @@ public function testQueryModifiedField() 'sortClauses' => [new SortClause\ContentId()], ] ); + self::assertInstanceOf(Criterion::class, $query->query); $query->query->setCustomField('user', 'first_name', 'custom_field'); $this->assertQueryFixture(