Find the best Rector rule to solve your problem. Searching through 1009 rules.
Found 7 rules:
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);
}
}
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.');
Turns old Constraint::$errorNames properties to use Constraint::ERROR_NAMES instead
use Symfony\Component\Validator\Constraints\NotBlank;
class SomeClass
{
- NotBlank::$errorNames
+ NotBlank::ERROR_NAMES
}
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);
}
}
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.',
- ]));
- }
}
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]);
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();