From b7f45efa02f9b54053fd12d21a7c741a0dc17db8 Mon Sep 17 00:00:00 2001 From: Anto Date: Wed, 10 Apr 2019 06:27:45 +0200 Subject: [PATCH] Simplify ExistsFilter declaration --- .../MongoDbOdm/Filter/ExistsFilter.php | 2 +- .../Doctrine/Orm/Filter/ExistsFilter.php | 30 +------------------ .../Resources/config/doctrine_mongodb_odm.xml | 2 +- .../Bundle/Resources/config/doctrine_orm.xml | 2 +- .../MongoDbOdm/Filter/ExistsFilterTest.php | 8 ++--- .../Doctrine/Orm/Filter/ExistsFilterTest.php | 10 +++---- 6 files changed, 13 insertions(+), 41 deletions(-) diff --git a/src/Bridge/Doctrine/MongoDbOdm/Filter/ExistsFilter.php b/src/Bridge/Doctrine/MongoDbOdm/Filter/ExistsFilter.php index 1fc3369bfdd..73eef88c5ad 100644 --- a/src/Bridge/Doctrine/MongoDbOdm/Filter/ExistsFilter.php +++ b/src/Bridge/Doctrine/MongoDbOdm/Filter/ExistsFilter.php @@ -39,7 +39,7 @@ final class ExistsFilter extends AbstractFilter implements ExistsFilterInterface { use ExistsFilterTrait; - public function __construct(ManagerRegistry $managerRegistry, LoggerInterface $logger = null, string $existsParameterName = self::QUERY_PARAMETER_KEY, array $properties = null) + public function __construct(ManagerRegistry $managerRegistry, LoggerInterface $logger = null, array $properties = null, string $existsParameterName = self::QUERY_PARAMETER_KEY) { parent::__construct($managerRegistry, $logger, $properties); diff --git a/src/Bridge/Doctrine/Orm/Filter/ExistsFilter.php b/src/Bridge/Doctrine/Orm/Filter/ExistsFilter.php index c4a16049b61..871a4704489 100644 --- a/src/Bridge/Doctrine/Orm/Filter/ExistsFilter.php +++ b/src/Bridge/Doctrine/Orm/Filter/ExistsFilter.php @@ -17,7 +17,6 @@ use ApiPlatform\Core\Bridge\Doctrine\Common\Filter\ExistsFilterTrait; use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryBuilderHelper; use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface; -use ApiPlatform\Core\Exception\InvalidArgumentException; use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Query\Expr\Join; @@ -42,35 +41,8 @@ class ExistsFilter extends AbstractContextAwareFilter implements ExistsFilterInt { use ExistsFilterTrait; - /** - * @param RequestStack|null $requestStack No prefix to prevent autowiring of this deprecated property - * @param mixed|null $properties - */ - public function __construct(ManagerRegistry $managerRegistry, $requestStack = null, LoggerInterface $logger = null, /* string $existsParameterName = self::QUERY_PARAMETER_KEY, array*/ $properties = null) + public function __construct(ManagerRegistry $managerRegistry, ?RequestStack $requestStack = null, LoggerInterface $logger = null, array $properties = null, string $existsParameterName = self::QUERY_PARAMETER_KEY) { - $existsParameterName = self::QUERY_PARAMETER_KEY; - - if (($funcNumArgs = \func_num_args()) > 3) { - $fourthArgument = func_get_arg(3); - if (4 <= $funcNumArgs && (null === $fourthArgument || \is_array($fourthArgument))) { - @trigger_error(sprintf('Passing the "$properties" argument as 4th argument of "%s" is deprecated since API Platform 2.5 and will not be possible anymore in API Platform 3. Pass the new "$existsParameterName" argument as 4th argument and the old "$properties" argument as 5th argument instead.', __CLASS__), E_USER_DEPRECATED); - $properties = $fourthArgument; - } elseif (\is_string($fourthArgument)) { - $existsParameterName = $fourthArgument; - } else { - throw new InvalidArgumentException(sprintf('The "$existsParameterName" argument of "%s" is expected to be a string.', __CLASS__)); - } - } - - if ($funcNumArgs > 4) { - $fifthArgument = func_get_arg(4); - if (null === $fifthArgument || \is_array($fifthArgument)) { - $properties = $fifthArgument; - } else { - throw new InvalidArgumentException(sprintf('The "$properties" argument of "%s" is expected to be an array or null.', __CLASS__)); - } - } - parent::__construct($managerRegistry, $requestStack, $logger, $properties); $this->existsParameterName = $existsParameterName; diff --git a/src/Bridge/Symfony/Bundle/Resources/config/doctrine_mongodb_odm.xml b/src/Bridge/Symfony/Bundle/Resources/config/doctrine_mongodb_odm.xml index 6ccf194c382..f95ffc1964f 100644 --- a/src/Bridge/Symfony/Bundle/Resources/config/doctrine_mongodb_odm.xml +++ b/src/Bridge/Symfony/Bundle/Resources/config/doctrine_mongodb_odm.xml @@ -86,7 +86,7 @@ - %api_platform.collection.exists_parameter_name% + %api_platform.collection.exists_parameter_name% diff --git a/src/Bridge/Symfony/Bundle/Resources/config/doctrine_orm.xml b/src/Bridge/Symfony/Bundle/Resources/config/doctrine_orm.xml index 8d4bbeab72d..51f7dd53978 100644 --- a/src/Bridge/Symfony/Bundle/Resources/config/doctrine_orm.xml +++ b/src/Bridge/Symfony/Bundle/Resources/config/doctrine_orm.xml @@ -99,7 +99,7 @@ null - %api_platform.collection.exists_parameter_name% + %api_platform.collection.exists_parameter_name% diff --git a/tests/Bridge/Doctrine/MongoDbOdm/Filter/ExistsFilterTest.php b/tests/Bridge/Doctrine/MongoDbOdm/Filter/ExistsFilterTest.php index 2ca6048675f..d824d8da5c8 100644 --- a/tests/Bridge/Doctrine/MongoDbOdm/Filter/ExistsFilterTest.php +++ b/tests/Bridge/Doctrine/MongoDbOdm/Filter/ExistsFilterTest.php @@ -113,10 +113,10 @@ public function testGetDescriptionDefaultFields() public function provideApplyTestData(): array { $existsFilterFactory = function (ManagerRegistry $managerRegistry, array $properties = null): ExistsFilter { - return new ExistsFilter($managerRegistry, null, 'exists', $properties); + return new ExistsFilter($managerRegistry, null, $properties, 'exists'); }; $customExistsFilterFactory = function (ManagerRegistry $managerRegistry, array $properties = null): ExistsFilter { - return new ExistsFilter($managerRegistry, null, 'customExists', $properties); + return new ExistsFilter($managerRegistry, null, $properties, 'customExists'); }; return array_merge_recursive( @@ -451,7 +451,7 @@ public function testLegacyExistsAfterSyntax() ], ], function (ManagerRegistry $managerRegistry, array $properties = null): ExistsFilter { - return new ExistsFilter($managerRegistry, null, 'exists', $properties); + return new ExistsFilter($managerRegistry, null, $properties, 'exists'); }, ]; @@ -460,6 +460,6 @@ function (ManagerRegistry $managerRegistry, array $properties = null): ExistsFil protected function buildFilter(?array $properties = null) { - return new $this->filterClass($this->managerRegistry, null, 'exists', $properties); + return new $this->filterClass($this->managerRegistry, null, $properties, 'exists'); } } diff --git a/tests/Bridge/Doctrine/Orm/Filter/ExistsFilterTest.php b/tests/Bridge/Doctrine/Orm/Filter/ExistsFilterTest.php index 7bfb3c83d8f..ac8ff833dfa 100644 --- a/tests/Bridge/Doctrine/Orm/Filter/ExistsFilterTest.php +++ b/tests/Bridge/Doctrine/Orm/Filter/ExistsFilterTest.php @@ -95,10 +95,10 @@ public function testGetDescriptionDefaultFields() public function provideApplyTestData(): array { $existsFilterFactory = function (ManagerRegistry $managerRegistry, array $properties = null, RequestStack $requestStack = null): ExistsFilter { - return new ExistsFilter($managerRegistry, $requestStack, null, 'exists', $properties); + return new ExistsFilter($managerRegistry, $requestStack, null, $properties, 'exists'); }; $customExistsFilterFactory = function (ManagerRegistry $managerRegistry, array $properties = null, RequestStack $requestStack = null): ExistsFilter { - return new ExistsFilter($managerRegistry, $requestStack, null, 'customExists', $properties); + return new ExistsFilter($managerRegistry, $requestStack, null, $properties, 'customExists'); }; return array_merge_recursive( @@ -245,7 +245,7 @@ public function testLegacyExistsAfterSyntax() sprintf('SELECT o FROM %s o WHERE o.description IS NOT NULL', Dummy::class), null, function (ManagerRegistry $managerRegistry, array $properties = null, RequestStack $requestStack = null): ExistsFilter { - return new ExistsFilter($managerRegistry, $requestStack, null, 'exists', $properties); + return new ExistsFilter($managerRegistry, $requestStack, null, $properties, 'exists'); }, ]; @@ -273,7 +273,7 @@ public function testLegacyRequest() sprintf('SELECT o FROM %s o WHERE o.description IS NOT NULL', Dummy::class), null, function (ManagerRegistry $managerRegistry, array $properties = null, RequestStack $requestStack = null): ExistsFilter { - return new ExistsFilter($managerRegistry, $requestStack, null, 'exists', $properties); + return new ExistsFilter($managerRegistry, $requestStack, null, $properties, 'exists'); }, ]; @@ -282,6 +282,6 @@ function (ManagerRegistry $managerRegistry, array $properties = null, RequestSta protected function buildFilter(?array $properties = null) { - return new $this->filterClass($this->managerRegistry, null, null, 'exists', $properties); + return new $this->filterClass($this->managerRegistry, null, null, $properties, 'exists'); } }