From e4c4d2dce80d7b1c1f487aca3a9f825872d5d713 Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Fri, 21 Jun 2019 10:29:21 +0200 Subject: [PATCH] [Validator] Add ExpressionValidator typehint & remove deprecation --- src/Symfony/Component/Validator/CHANGELOG.md | 1 + .../Constraints/ExpressionValidator.php | 14 +------ .../Constraints/ExpressionValidatorTest.php | 37 ------------------- 3 files changed, 2 insertions(+), 50 deletions(-) diff --git a/src/Symfony/Component/Validator/CHANGELOG.md b/src/Symfony/Component/Validator/CHANGELOG.md index 324d212792..18b9330f9b 100644 --- a/src/Symfony/Component/Validator/CHANGELOG.md +++ b/src/Symfony/Component/Validator/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG 5.0.0 ----- + * an `ExpressionLanguage` instance or null must be passed as the first argument of `ExpressionValidator::__construct()` * removed the `checkDNS` and `dnsMessage` options of the `Url` constraint * removed the `checkMX`, `checkHost` and `strict` options of the `Email` constraint * removed support for validating instances of `\DateTimeInterface` in `DateTimeValidator`, `DateValidator` and `TimeValidator` diff --git a/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php b/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php index ff572fce17..feeed1831d 100644 --- a/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php @@ -24,20 +24,8 @@ class ExpressionValidator extends ConstraintValidator { private $expressionLanguage; - public function __construct(/*ExpressionLanguage */$expressionLanguage = null) + public function __construct(ExpressionLanguage $expressionLanguage = null) { - if (\func_num_args() > 1) { - @trigger_error(sprintf('The "%s" instance should be passed as "%s" first argument instead of second argument since 4.4.', ExpressionLanguage::class, __METHOD__), E_USER_DEPRECATED); - - $expressionLanguage = func_get_arg(1); - - if (null !== $expressionLanguage && !$expressionLanguage instanceof ExpressionLanguage) { - throw new \TypeError(sprintf('Argument 2 passed to %s() must be an instance of %s or null, %s given. Since 4.4, passing it as the second argument is deprecated and will trigger a deprecation. Pass it as the first argument instead.', __METHOD__, ExpressionLanguage::class, \is_object($expressionLanguage) ? \get_class($expressionLanguage) : \gettype($expressionLanguage))); - } - } elseif (null !== $expressionLanguage && !$expressionLanguage instanceof ExpressionLanguage) { - @trigger_error(sprintf('The "%s" first argument must be an instance of "%s" or null since 4.4. "%s" given', __METHOD__, ExpressionLanguage::class, \is_object($expressionLanguage) ? \get_class($expressionLanguage) : \gettype($expressionLanguage)), E_USER_DEPRECATED); - } - $this->expressionLanguage = $expressionLanguage; } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php index e1507fa8e9..280757b8e9 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php @@ -272,43 +272,6 @@ class ExpressionValidatorTest extends ConstraintValidatorTestCase $this->assertTrue($used, 'Failed asserting that custom ExpressionLanguage instance is used.'); } - /** - * @group legacy - * @expectedDeprecation The "Symfony\Component\ExpressionLanguage\ExpressionLanguage" instance should be passed as "Symfony\Component\Validator\Constraints\ExpressionValidator::__construct" first argument instead of second argument since 4.4. - */ - public function testLegacyExpressionLanguageUsage() - { - $constraint = new Expression([ - 'expression' => 'false', - ]); - - $expressionLanguage = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ExpressionLanguage')->getMock(); - - $used = false; - - $expressionLanguage->method('evaluate') - ->willReturnCallback(function () use (&$used) { - $used = true; - - return true; - }); - - $validator = new ExpressionValidator(null, $expressionLanguage); - $validator->initialize($this->createContext()); - $validator->validate(null, $constraint); - - $this->assertTrue($used, 'Failed asserting that custom ExpressionLanguage instance is used.'); - } - - /** - * @group legacy - * @expectedDeprecation The "Symfony\Component\Validator\Constraints\ExpressionValidator::__construct" first argument must be an instance of "Symfony\Component\ExpressionLanguage\ExpressionLanguage" or null since 4.4. "string" given - */ - public function testConstructorInvalidType() - { - new ExpressionValidator('foo'); - } - public function testPassingCustomValues() { $constraint = new Expression([