Skip to content

Commit

Permalink
minor #35816 [Validator] Remove specific check for Valid targets (ogi…
Browse files Browse the repository at this point in the history
…zanagi)

This PR was merged into the 3.4 branch.

Discussion
----------

[Validator] Remove specific check for Valid targets

| Q             | A
| ------------- | ---
| Branch?       | 3.4 <!-- see below -->
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | N/A <!-- prefix each issue number with "Fix #", if any -->
| License       | MIT
| Doc PR        | N/A

As covered by `ClassMetadataTest::testAddConstraintDoesNotAcceptValid`, this check is useless, as `Valid` already accepts only properties as targets.

This check is a [leftover of a time](9b07b0c) `Valid` was extending `Traverse` which was allowing classes & properties.
The `Valid` targets are properly checked by the lines above, the same way as other constraints.

Commits
-------

0086562 [Validator] Remove specific check for Valid targets
  • Loading branch information
nicolas-grekas committed Feb 23, 2020
2 parents 1676e3a + 0086562 commit f75be00
Showing 1 changed file with 0 additions and 5 deletions.
5 changes: 0 additions & 5 deletions src/Symfony/Component/Validator/Mapping/ClassMetadata.php
Expand Up @@ -14,7 +14,6 @@
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\GroupSequence;
use Symfony\Component\Validator\Constraints\Traverse;
use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
use Symfony\Component\Validator\Exception\GroupDefinitionException;

Expand Down Expand Up @@ -183,10 +182,6 @@ public function addConstraint(Constraint $constraint)
throw new ConstraintDefinitionException(sprintf('The constraint "%s" cannot be put on classes.', \get_class($constraint)));
}

if ($constraint instanceof Valid) {
throw new ConstraintDefinitionException(sprintf('The constraint "%s" cannot be put on classes.', \get_class($constraint)));
}

if ($constraint instanceof Traverse) {
if ($constraint->traverse) {
// If traverse is true, traversal should be explicitly enabled
Expand Down

0 comments on commit f75be00

Please sign in to comment.