8000 minor #47597 [Validator] Improve WhenValidator CS (HeahDude) · upyx/symfony@34072fa · GitHub
[go: up one dir, main page]

Skip to content

Commit 34072fa

Browse files
committed
minor symfony#47597 [Validator] Improve WhenValidator CS (HeahDude)
This PR was merged into the 6.2 branch. Discussion ---------- [Validator] Improve WhenValidator CS | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | ~ | License | MIT | Doc PR | ~ Commits ------- 2d1a005 [Validator] Improve WhenValidator CS
2 parents 8570ce0 + 2d1a005 commit 34072fa

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

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

Lines changed: 2 additions & 12 deletions
20
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,10 @@
1919

20
final class WhenValidator extends ConstraintValidator
2121
{
22-
private ?ExpressionLanguage $expressionLanguage;
23-
24-
public function __construct(ExpressionLanguage $expressionLanguage = null)
22+
public function __construct(private ?ExpressionLanguage $expressionLanguage = null)
2523
{
26-
$this->expressionLanguage = $expressionLanguage;
2724
}
2825

29-
/**
30-
* {@inheritdoc}
31-
*/
3226
public function validate(mixed $value, Constraint $constraint): void
3327
{
3428
if (!$constraint instanceof When) {
@@ -48,14 +42,10 @@ public function validate(mixed $value, Constraint $constraint): void
4842

4943
private function getExpressionLanguage(): ExpressionLanguage
5044
{
51-
if (null !== $this->expressionLanguage) {
52-
return $this->expressionLanguage;
53-
}
54-
5545
if (!class_exists(ExpressionLanguage::class)) {
5646
throw new LogicException(sprintf('The "symfony/expression-language" component is required to use the "%s" validator. Try running "composer require symfony/expression-language".', __CLASS__));
5747
}
5848

59-
return $this->expressionLanguage = new ExpressionLanguage();
49+
return $this->expressionLanguage ??= new ExpressionLanguage();
6050
}
6151
}

0 commit comments

Comments
 (0)
0