8000 minor #32128 [Validator] Add ExpressionValidator typehint & remove de… · symfony/symfony@2f9e69e · GitHub
[go: up one dir, main page]

Skip to content

Commit 2f9e69e

Browse files
committed
minor #32128 [Validator] Add ExpressionValidator typehint & remove deprecation (ogizanagi)
This PR was merged into the 5.0-dev branch. Discussion ---------- [Validator] Add ExpressionValidator typehint & remove deprecation | Q | A | ------------- | --- | Branch? | master <!-- see below --> | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #32041 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | N/A Commits ------- e4c4d2d [Validator] Add ExpressionValidator typehint & remove deprecation
2 parents 1ac9cc2 + e4c4d2d commit 2f9e69e

File tree

3 files changed

+2
-50
lines changed

3 files changed

+2
-50
lines changed

src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
5.0.0
55
-----
66

7+
* an `ExpressionLanguage` instance or null must be passed as the first argument of `ExpressionValidator::__construct()`
78
* removed the `checkDNS` and `dnsMessage` options of the `Url` constraint
89
* removed the `checkMX`, `checkHost` and `strict` options of the `Email` constraint
910
* removed support for validating instances of `\DateTimeInterface` in `DateTimeValidator`, `DateValidator` and `TimeValidator`

src/Symfony/Component/Validator/Constraints/ExpressionValidator.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,8 @@ class ExpressionValidator extends ConstraintValidator
2424
{
2525
private $expressionLanguage;
2626

27-
public function __construct(/*ExpressionLanguage */$expressionLanguage = null)
27+
public function __construct(ExpressionLanguage $expressionLanguage = null)
2828
{
29-
if (\func_num_args() > 1) {
30-
@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);
31-
32-
$expressionLanguage = func_get_arg(1);
33-
34-
if (null !== $expressionLanguage && !$expressionLanguage instanceof ExpressionLanguage) {
35-
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)));
36-
}
37-
} elseif (null !== $expressionLanguage && !$expressionLanguage instanceof ExpressionLanguage) {
38-
@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);
39-
}
40-
4129
$this->expressionLanguage = $expressionLanguage;
4230
}
4331

src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -272,43 +272,6 @@ public function testExpressionLanguageUsage()
272272
$this->assertTrue($used, 'Failed asserting that custom ExpressionLanguage instance is used.');
273273
}
274274

275-
/**
276-
* @group legacy
277-
* @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.
278-
*/
279-
public function testLegacyExpressionLanguageUsage()
280-
{
281-
$constraint = new Expression([
282-
'expression' => 'false',
283-
]);
284-
285-
$expressionLanguage = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ExpressionLanguage')->getMock();
286-
287-
$used = false;
288-
289-
$expressionLanguage->method('evaluate')
290-
->willReturnCallback(function () use (&$used) {
291-
$used = true;
292-
293-
return true;
294-
});
295-
296-
$validator = new ExpressionValidator(null, $expressionLanguage);
297-
$validator->initialize($this->createContext());
298-
$validator->validate(null, $constraint);
299-
300-
$this->assertTrue($used, 'Failed asserting that custom ExpressionLanguage instance is used.');
301-
}
302-
303-
/**
304-
* @group legacy
305-
* @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
306-
*/
307-
public function testConstructorInvalidType()
308-
{
309-
new ExpressionValidator('foo');
310-
}
311-
312275
public function testPassingCustomValues()
313276
{
314277
$constraint = new Expression([

0 commit comments

Comments
 (0)
0