Find the best Rector rule to solve your problem. Searching through 1009 rules.

Found 7 rules:

ConstraintValidatorValidateToValidateInContextRector

Migrate deprecated ConstraintValidatorInterface::validate() in ConstraintValidatorTestCase tests to $this->validate(), otherwise to validateInContext() (Symfony 8.1+).

 use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;

 final class SomeValidatorTest extends ConstraintValidatorTestCase
 {
     public function test(): void
     {
-        $this->validator->validate($value, $constraint);
+        $this->validate($value, $constraint);
     }
 }
PACKAGE:  symfony/validator >=8.1

ConstraintOptionsToNamedArgumentsRector

Refactor Symfony constraints using array options to named arguments syntax for better readability and type safety.

 use Symfony\Component\Validator\Constraints\NotBlank;

-$constraint = new NotBlank(['message' => 'This field should not be blank.']);
+$constraint = new NotBlank(message: 'This field should not be blank.');
PACKAGE:  symfony/validator >=7.3

ErrorNamesPropertyToConstantRector

Turns old Constraint::$errorNames properties to use Constraint::ERROR_NAMES instead

 use Symfony\Component\Validator\Constraints\NotBlank;

 class SomeClass
 {
-    NotBlank::$errorNames
+    NotBlank::ERROR_NAMES

 }
PACKAGE:  symfony/validator >=6.1

ValidatorBuilderEnableAnnotationMappingRector

Migrates from deprecated ValidatorBuilder->enableAnnotationMapping($reader) to ValidatorBuilder->enableAnnotationMapping(true)->setDoctrineAnnotationReader($reader)

 use Doctrine\Common\Annotations\Reader;
 use Symfony\Component\Validator\ValidatorBuilder;

 class SomeClass
 {
     public function run(ValidatorBuilder $builder, Reader $reader)
     {
-        $builder->enableAnnotationMapping($reader);
+        $builder->enableAnnotationMapping(true)->setDoctrineAnnotationReader($reader);
     }
 }
PACKAGE:  symfony/validator >=5.2

LoadValidatorMetadataToAttributeRector

Move metadata from loadValidatorMetadata() to property/getter/class attributes

 use Symfony\Component\Validator\Constraints as Assert;
 use Symfony\Component\Validator\Mapping\ClassMetadata;

 final class SomeClass
 {
+    #[Assert\NotBlank(message: 'City can\'t be blank.')]
     private $city;
-
-    public static function loadValidatorMetadata(ClassMetadata $metadata): void
-    {
-        $metadata->addPropertyConstraint('city', new Assert\NotBlank([
-            'message' => 'City can\'t be blank.',
-        ]));
-    }
 }
PACKAGE:  symfony/validator >=5.2

ConstraintUrlOptionRector

Turns true value to Url::CHECK_DNS_TYPE_ANY in Validator in Symfony.

-$constraint = new Url(["checkDNS" => true]);
+$constraint = new Url(["checkDNS" => Url::CHECK_DNS_TYPE_ANY]);
PACKAGE:  symfony/validator >=4.0

AddViolationToBuildViolationRector

Change $context->addViolationAt to $context->buildViolation on Validator ExecutionContext

-$context->addViolationAt('property', 'The value {{ value }} is invalid.', array(
-    '{{ value }}' => $invalidValue,
-));
+$context->buildViolation('The value {{ value }} is invalid.')
+    ->atPath('property')
+    ->setParameter('{{ value }}', $invalidValue)
+    ->addViolation();
PACKAGE:  symfony/validator >=2.5