From aa317b2f1974c1ad7c9a7c745347cb6533123ecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Pimpa=CC=83o?= Date: Mon, 8 Dec 2025 12:20:32 +0000 Subject: [PATCH 1/4] chore: bump symfony/validator to version 8.0 --- .ddev/config.yaml | 2 +- composer.json | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.ddev/config.yaml b/.ddev/config.yaml index d761a8e..044e458 100644 --- a/.ddev/config.yaml +++ b/.ddev/config.yaml @@ -1,7 +1,7 @@ name: fluent-validator type: php docroot: "" -php_version: "8.2" +php_version: "8.4" webserver_type: nginx-fpm xdebug_enabled: false additional_hostnames: [] diff --git a/composer.json b/composer.json index c4914d4..d929d46 100644 --- a/composer.json +++ b/composer.json @@ -6,21 +6,21 @@ "license": "MIT", "authors": [ { - "name": "André Pimpão", - "email": "a.pimpao@programmator.dev", + "name": "Programmator", + "email": "hotline@programmator.dev", "homepage": "https://programmator.dev" } ], "require": { - "php": ">=8.2", - "symfony/config": "^7.3", - "symfony/translation": "^7.3", - "symfony/validator": "^7.3" + "php": ">=8.4", + "symfony/config": "^8.0", + "symfony/translation": "^8.0", + "symfony/validator": "^8.0" }, "require-dev": { "phpunit/phpunit": "^11.5", - "symfony/console": "^7.3", - "symfony/var-dumper": "^7.3", + "symfony/console": "^8.0", + "symfony/var-dumper": "^8.0", "wyrihaximus/list-classes-in-directory": "^1.7" }, "autoload": { From 4ed19a7060ff413f3055a2bc2a1184b4bde66c7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Pimpa=CC=83o?= Date: Mon, 8 Dec 2025 12:54:14 +0000 Subject: [PATCH 2/4] chore: update and fix interfaces generator --- bin/console | 6 +- src/ChainedValidatorInterface.php | 108 ++++++++++++------ ...CreateChainedValidatorInterfaceCommand.php | 2 +- .../CreateStaticValidatorInterfaceCommand.php | 2 +- src/StaticValidatorInterface.php | 108 ++++++++++++------ tests/ValidatorTest.php | 6 +- 6 files changed, 148 insertions(+), 84 deletions(-) diff --git a/bin/console b/bin/console index 189d309..715ef65 100644 --- a/bin/console +++ b/bin/console @@ -11,8 +11,8 @@ require __DIR__ . '/../vendor/autoload.php'; $app = new Application(); -$app->add(new CreateStaticValidatorInterfaceCommand()); -$app->add(new CreateChainedValidatorInterfaceCommand()); -$app->add(new CreateValidatorInterfacesCommand()); +$app->addCommand(new CreateStaticValidatorInterfaceCommand()); +$app->addCommand(new CreateChainedValidatorInterfaceCommand()); +$app->addCommand(new CreateValidatorInterfacesCommand()); $app->run(); \ No newline at end of file diff --git a/src/ChainedValidatorInterface.php b/src/ChainedValidatorInterface.php index e974133..e4e215e 100644 --- a/src/ChainedValidatorInterface.php +++ b/src/ChainedValidatorInterface.php @@ -5,13 +5,13 @@ interface ChainedValidatorInterface { public function all( - mixed $constraints = null, + \Symfony\Component\Validator\Constraint|array|null $constraints = null, ?array $groups = null, mixed $payload = null, ): ChainedValidatorInterface&Validator; public function atLeastOneOf( - mixed $constraints = null, + \Symfony\Component\Validator\Constraint|array|null $constraints = null, ?array $groups = null, mixed $payload = null, ?string $message = null, @@ -38,10 +38,9 @@ public function blank( ): ChainedValidatorInterface&Validator; public function callback( - callable|array|string|null $callback = null, + callable|string|null $callback = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public function cardScheme( @@ -49,12 +48,10 @@ public function cardScheme( ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public function cascade( array|string|null $exclude = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public function charset( @@ -65,7 +62,7 @@ public function charset( ): ChainedValidatorInterface&Validator; public function choice( - array|string $options = [], + array|string|null $options = null, ?array $choices = null, callable|string|null $callback = null, ?bool $multiple = null, @@ -93,7 +90,7 @@ public function cidr( ): ChainedValidatorInterface&Validator; public function collection( - mixed $fields = null, + ?array $fields = null, ?array $groups = null, mixed $payload = null, ?bool $allowExtraFields = null, @@ -103,7 +100,7 @@ public function collection( ): ChainedValidatorInterface&Validator; public function count( - array|int|null $exactly = null, + ?int $exactly = null, ?int $min = null, ?int $max = null, ?int $divisibleBy = null, @@ -113,7 +110,6 @@ public function count( ?string $divisibleByMessage = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public function country( @@ -129,7 +125,6 @@ public function cssColor( ?string $message = null, ?array $groups = null, $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public function currency( @@ -147,11 +142,10 @@ public function date( ): ChainedValidatorInterface&Validator; public function dateTime( - array|string|null $format = null, + ?string $format = null, ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public function disableAutoMapping( @@ -165,7 +159,6 @@ public function divisibleBy( ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public function email( @@ -188,11 +181,10 @@ public function equalTo( ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public function expression( - \Symfony\Component\ExpressionLanguage\Expression|array|string|null $expression, + \Symfony\Component\ExpressionLanguage\Expression|string|null $expression, ?string $message = null, ?array $values = null, ?array $groups = null, @@ -245,7 +237,6 @@ public function greaterThan( ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public function greaterThanOrEqual( @@ -254,7 +245,6 @@ public function greaterThanOrEqual( ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public function hostname( @@ -278,7 +268,6 @@ public function identicalTo( ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public function image( @@ -366,14 +355,13 @@ public function isTrue( ): ChainedValidatorInterface&Validator; public function isbn( - array|string|null $type = null, + ?string $type = null, ?string $message = null, ?string $isbn10Message = null, ?string $isbn13Message = null, ?string $bothIsbnMessage = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public function isin( @@ -408,7 +396,7 @@ public function language( ): ChainedValidatorInterface&Validator; public function length( - array|int|null $exactly = null, + ?int $exactly = null, ?int $min = null, ?int $max = null, ?string $charset = null, @@ -420,7 +408,6 @@ public function length( ?string $charsetMessage = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public function lessThan( @@ -429,7 +416,6 @@ public function lessThan( ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public function lessThanOrEqual( @@ -438,7 +424,6 @@ public function lessThanOrEqual( ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public function locale( @@ -515,7 +500,6 @@ public function notEqualTo( ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public function notIdenticalTo( @@ -524,7 +508,6 @@ public function notIdenticalTo( ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public function notNull( @@ -535,7 +518,7 @@ public function notNull( ): ChainedValidatorInterface&Validator; public function optional( - mixed $options = null, + \Symfony\Component\Validator\Constraint|array $constraints = [], ?array $groups = null, mixed $payload = null, ): ChainedValidatorInterface&Validator; @@ -578,24 +561,23 @@ public function range( ): ChainedValidatorInterface&Validator; public function regex( - array|string|null $pattern, + ?string $pattern, ?string $message = null, ?string $htmlPattern = null, ?bool $match = null, ?callable $normalizer = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public function required( - mixed $options = null, + \Symfony\Component\Validator\Constraint|array $constraints = [], ?array $groups = null, mixed $payload = null, ): ChainedValidatorInterface&Validator; public function sequentially( - mixed $constraints = null, + \Symfony\Component\Validator\Constraint|array|null $constraints = null, ?array $groups = null, mixed $payload = null, ): ChainedValidatorInterface&Validator; @@ -609,17 +591,16 @@ public function time( ): ChainedValidatorInterface&Validator; public function timezone( - array|int|null $zone = null, + ?int $zone = null, ?string $message = null, ?string $countryCode = null, ?bool $intlCompatible = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public function traverse( - array|bool|null $traverse = null, + ?bool $traverse = null, mixed $payload = null, ): ChainedValidatorInterface&Validator; @@ -628,7 +609,6 @@ public function type( ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public function ulid( @@ -653,7 +633,7 @@ public function unique( public function url( ?array $options = null, ?string $message = null, - ?array $protocols = null, + array|string|null $protocols = null, ?bool $relativeProtocol = null, ?callable $normalizer = null, ?array $groups = null, @@ -679,6 +659,58 @@ public function valid( ?bool $traverse = null, ): ChainedValidatorInterface&Validator; + public function video( + string|int|null $maxSize = null, + ?bool $binaryFormat = null, + array|string|null $mimeTypes = null, + ?int $filenameMaxLength = null, + ?int $minWidth = null, + ?int $maxWidth = null, + ?int $maxHeight = null, + ?int $minHeight = null, + int|float|null $maxRatio = null, + int|float|null $minRatio = null, + int|float|null $minPixels = null, + int|float|null $maxPixels = null, + ?bool $allowSquare = null, + ?bool $allowLandscape = null, + ?bool $allowPortrait = null, + ?array $allowedCodecs = null, + ?array $allowedContainers = null, + ?string $notFoundMessage = null, + ?string $notReadableMessage = null, + ?string $maxSizeMessage = null, + ?string $mimeTypesMessage = null, + ?string $disallowEmptyMessage = null, + ?string $filenameTooLongMessage = null, + ?string $uploadIniSizeErrorMessage = null, + ?string $uploadFormSizeErrorMessage = null, + ?string $uploadPartialErrorMessage = null, + ?string $uploadNoFileErrorMessage = null, + ?string $uploadNoTmpDirErrorMessage = null, + ?string $uploadCantWriteErrorMessage = null, + ?string $uploadExtensionErrorMessage = null, + ?string $uploadErrorMessage = null, + ?string $sizeNotDetectedMessage = null, + ?string $maxWidthMessage = null, + ?string $minWidthMessage = null, + ?string $maxHeightMessage = null, + ?string $minHeightMessage = null, + ?string $minPixelsMessage = null, + ?string $maxPixelsMessage = null, + ?string $maxRatioMessage = null, + ?string $minRatioMessage = null, + ?string $allowSquareMessage = null, + ?string $allowLandscapeMessage = null, + ?string $allowPortraitMessage = null, + ?string $corruptedMessage = null, + ?string $multipleVideoStreamsMessage = null, + ?string $unsupportedCodecMessage = null, + ?string $unsupportedContainerMessage = null, + ?array $groups = null, + mixed $payload = null, + ): ChainedValidatorInterface&Validator; + public function week( ?string $min = null, ?string $max = null, @@ -691,7 +723,7 @@ public function week( ): ChainedValidatorInterface&Validator; public function when( - \Symfony\Component\ExpressionLanguage\Expression|Closure|array|string $expression, + \Symfony\Component\ExpressionLanguage\Expression|Closure|string $expression, \Symfony\Component\Validator\Constraint|array|null $constraints = null, ?array $values = null, ?array $groups = null, diff --git a/src/Command/CreateChainedValidatorInterfaceCommand.php b/src/Command/CreateChainedValidatorInterfaceCommand.php index 62320f8..27356fd 100644 --- a/src/Command/CreateChainedValidatorInterfaceCommand.php +++ b/src/Command/CreateChainedValidatorInterfaceCommand.php @@ -25,8 +25,8 @@ public function execute(InputInterface $input, OutputInterface $output): int $packagePath = InstalledVersions::getInstallPath('symfony/validator'); $constraintsPath = sprintf('%s/Constraints', $packagePath); $classes = Lister::instantiatableClassesInDirectory($constraintsPath); - $file = new InterfaceWriter('ChainedValidatorInterface'); + $file->writeInterfaceStart(); foreach ($classes as $class) { diff --git a/src/Command/CreateStaticValidatorInterfaceCommand.php b/src/Command/CreateStaticValidatorInterfaceCommand.php index d1a776d..32e2c16 100644 --- a/src/Command/CreateStaticValidatorInterfaceCommand.php +++ b/src/Command/CreateStaticValidatorInterfaceCommand.php @@ -25,8 +25,8 @@ public function execute(InputInterface $input, OutputInterface $output): int $packagePath = InstalledVersions::getInstallPath('symfony/validator'); $constraintsPath = sprintf('%s/Constraints', $packagePath); $classes = Lister::instantiatableClassesInDirectory($constraintsPath); - $file = new InterfaceWriter('StaticValidatorInterface'); + $file->writeInterfaceStart(); foreach ($classes as $class) { diff --git a/src/StaticValidatorInterface.php b/src/StaticValidatorInterface.php index a8d1b32..5e651e9 100644 --- a/src/StaticValidatorInterface.php +++ b/src/StaticValidatorInterface.php @@ -5,13 +5,13 @@ interface StaticValidatorInterface { public static function all( - mixed $constraints = null, + \Symfony\Component\Validator\Constraint|array|null $constraints = null, ?array $groups = null, mixed $payload = null, ): ChainedValidatorInterface&Validator; public static function atLeastOneOf( - mixed $constraints = null, + \Symfony\Component\Validator\Constraint|array|null $constraints = null, ?array $groups = null, mixed $payload = null, ?string $message = null, @@ -38,10 +38,9 @@ public static function blank( ): ChainedValidatorInterface&Validator; public static function callback( - callable|array|string|null $callback = null, + callable|string|null $callback = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public static function cardScheme( @@ -49,12 +48,10 @@ public static function cardScheme( ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public static function cascade( array|string|null $exclude = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public static function charset( @@ -65,7 +62,7 @@ public static function charset( ): ChainedValidatorInterface&Validator; public static function choice( - array|string $options = [], + array|string|null $options = null, ?array $choices = null, callable|string|null $callback = null, ?bool $multiple = null, @@ -93,7 +90,7 @@ public static function cidr( ): ChainedValidatorInterface&Validator; public static function collection( - mixed $fields = null, + ?array $fields = null, ?array $groups = null, mixed $payload = null, ?bool $allowExtraFields = null, @@ -103,7 +100,7 @@ public static function collection( ): ChainedValidatorInterface&Validator; public static function count( - array|int|null $exactly = null, + ?int $exactly = null, ?int $min = null, ?int $max = null, ?int $divisibleBy = null, @@ -113,7 +110,6 @@ public static function count( ?string $divisibleByMessage = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public static function country( @@ -129,7 +125,6 @@ public static function cssColor( ?string $message = null, ?array $groups = null, $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public static function currency( @@ -147,11 +142,10 @@ public static function date( ): ChainedValidatorInterface&Validator; public static function dateTime( - array|string|null $format = null, + ?string $format = null, ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public static function disableAutoMapping( @@ -165,7 +159,6 @@ public static function divisibleBy( ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public static function email( @@ -188,11 +181,10 @@ public static function equalTo( ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public static function expression( - \Symfony\Component\ExpressionLanguage\Expression|array|string|null $expression, + \Symfony\Component\ExpressionLanguage\Expression|string|null $expression, ?string $message = null, ?array $values = null, ?array $groups = null, @@ -245,7 +237,6 @@ public static function greaterThan( ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public static function greaterThanOrEqual( @@ -254,7 +245,6 @@ public static function greaterThanOrEqual( ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public static function hostname( @@ -278,7 +268,6 @@ public static function identicalTo( ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public static function image( @@ -366,14 +355,13 @@ public static function isTrue( ): ChainedValidatorInterface&Validator; public static function isbn( - array|string|null $type = null, + ?string $type = null, ?string $message = null, ?string $isbn10Message = null, ?string $isbn13Message = null, ?string $bothIsbnMessage = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public static function isin( @@ -408,7 +396,7 @@ public static function language( ): ChainedValidatorInterface&Validator; public static function length( - array|int|null $exactly = null, + ?int $exactly = null, ?int $min = null, ?int $max = null, ?string $charset = null, @@ -420,7 +408,6 @@ public static function length( ?string $charsetMessage = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public static function lessThan( @@ -429,7 +416,6 @@ public static function lessThan( ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public static function lessThanOrEqual( @@ -438,7 +424,6 @@ public static function lessThanOrEqual( ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public static function locale( @@ -515,7 +500,6 @@ public static function notEqualTo( ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public static function notIdenticalTo( @@ -524,7 +508,6 @@ public static function notIdenticalTo( ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public static function notNull( @@ -535,7 +518,7 @@ public static function notNull( ): ChainedValidatorInterface&Validator; public static function optional( - mixed $options = null, + \Symfony\Component\Validator\Constraint|array $constraints = [], ?array $groups = null, mixed $payload = null, ): ChainedValidatorInterface&Validator; @@ -578,24 +561,23 @@ public static function range( ): ChainedValidatorInterface&Validator; public static function regex( - array|string|null $pattern, + ?string $pattern, ?string $message = null, ?string $htmlPattern = null, ?bool $match = null, ?callable $normalizer = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public static function required( - mixed $options = null, + \Symfony\Component\Validator\Constraint|array $constraints = [], ?array $groups = null, mixed $payload = null, ): ChainedValidatorInterface&Validator; public static function sequentially( - mixed $constraints = null, + \Symfony\Component\Validator\Constraint|array|null $constraints = null, ?array $groups = null, mixed $payload = null, ): ChainedValidatorInterface&Validator; @@ -609,17 +591,16 @@ public static function time( ): ChainedValidatorInterface&Validator; public static function timezone( - array|int|null $zone = null, + ?int $zone = null, ?string $message = null, ?string $countryCode = null, ?bool $intlCompatible = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public static function traverse( - array|bool|null $traverse = null, + ?bool $traverse = null, mixed $payload = null, ): ChainedValidatorInterface&Validator; @@ -628,7 +609,6 @@ public static function type( ?string $message = null, ?array $groups = null, mixed $payload = null, - ?array $options = null, ): ChainedValidatorInterface&Validator; public static function ulid( @@ -653,7 +633,7 @@ public static function unique( public static function url( ?array $options = null, ?string $message = null, - ?array $protocols = null, + array|string|null $protocols = null, ?bool $relativeProtocol = null, ?callable $normalizer = null, ?array $groups = null, @@ -679,6 +659,58 @@ public static function valid( ?bool $traverse = null, ): ChainedValidatorInterface&Validator; + public static function video( + string|int|null $maxSize = null, + ?bool $binaryFormat = null, + array|string|null $mimeTypes = null, + ?int $filenameMaxLength = null, + ?int $minWidth = null, + ?int $maxWidth = null, + ?int $maxHeight = null, + ?int $minHeight = null, + int|float|null $maxRatio = null, + int|float|null $minRatio = null, + int|float|null $minPixels = null, + int|float|null $maxPixels = null, + ?bool $allowSquare = null, + ?bool $allowLandscape = null, + ?bool $allowPortrait = null, + ?array $allowedCodecs = null, + ?array $allowedContainers = null, + ?string $notFoundMessage = null, + ?string $notReadableMessage = null, + ?string $maxSizeMessage = null, + ?string $mimeTypesMessage = null, + ?string $disallowEmptyMessage = null, + ?string $filenameTooLongMessage = null, + ?string $uploadIniSizeErrorMessage = null, + ?string $uploadFormSizeErrorMessage = null, + ?string $uploadPartialErrorMessage = null, + ?string $uploadNoFileErrorMessage = null, + ?string $uploadNoTmpDirErrorMessage = null, + ?string $uploadCantWriteErrorMessage = null, + ?string $uploadExtensionErrorMessage = null, + ?string $uploadErrorMessage = null, + ?string $sizeNotDetectedMessage = null, + ?string $maxWidthMessage = null, + ?string $minWidthMessage = null, + ?string $maxHeightMessage = null, + ?string $minHeightMessage = null, + ?string $minPixelsMessage = null, + ?string $maxPixelsMessage = null, + ?string $maxRatioMessage = null, + ?string $minRatioMessage = null, + ?string $allowSquareMessage = null, + ?string $allowLandscapeMessage = null, + ?string $allowPortraitMessage = null, + ?string $corruptedMessage = null, + ?string $multipleVideoStreamsMessage = null, + ?string $unsupportedCodecMessage = null, + ?string $unsupportedContainerMessage = null, + ?array $groups = null, + mixed $payload = null, + ): ChainedValidatorInterface&Validator; + public static function week( ?string $min = null, ?string $max = null, @@ -691,7 +723,7 @@ public static function week( ): ChainedValidatorInterface&Validator; public static function when( - \Symfony\Component\ExpressionLanguage\Expression|Closure|array|string $expression, + \Symfony\Component\ExpressionLanguage\Expression|Closure|string $expression, \Symfony\Component\Validator\Constraint|array|null $constraints = null, ?array $values = null, ?array $groups = null, diff --git a/tests/ValidatorTest.php b/tests/ValidatorTest.php index 80b14c2..323bec1 100644 --- a/tests/ValidatorTest.php +++ b/tests/ValidatorTest.php @@ -27,7 +27,7 @@ protected function setUp(): void public function testConstraintThatIsInvalid(): void { // NotBlankValidator class exists in "Symfony\Component\Validator\Constraints" namespace - // but throws error because it is not an instance of Constraint + // but throws an error because it is not an instance of Constraint $this->expectException(NoSuchConstraintException::class); Validator::notBlankValidator(); } @@ -86,13 +86,13 @@ public function testCustomConstraint(): void public function testSetTranslator(): void { - // by default, error is in English + // by default, the error is in English $violations = $this->validator->validate(''); $this->assertEquals('This value should not be blank.', $violations->get(0)->getMessage()); // set translator and then try again Validator::setTranslator(new Translator('pt')); - // now error is in Portuguese + // now the error is in Portuguese $violations = $this->validator->validate(''); $this->assertEquals('Este valor não deveria ser vazio.', $violations->get(0)->getMessage()); } From e36248ee4c521d7793f9a99cec156c8d77d66c7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Pimpa=CC=83o?= Date: Mon, 8 Dec 2025 13:03:25 +0000 Subject: [PATCH 3/4] docs: update requirements and grammar improvements --- README.md | 15 +++++++++------ src/Validator.php | 6 +++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index cb154aa..b2f843b 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,15 @@ A [Symfony Validator](https://symfony.com/doc/current/validation.html) wrapper that enables fluent-style validation for raw values, offering an easy-to-use and intuitive API to validate user input or other data in a concise and readable manner. +> [!NOTE] +> This library will always (try to) be in sync with the latest Symfony Validator version. + ## Features - 🌊 **Fluent-style validation:** Chain validation methods for better readability and flow. - 🤘 **Constraints autocompletion:** Enables IDE autocompletion for available constraints. - 🔥 **Three validation methods:** Use `validate`, `assert`, or `isValid` based on the context (i.e., collect errors or throw exceptions). -- ⚙️ **Custom constraints:** Easily integrate custom validation logic with Symfony's Validator system. +- ⚙️ **Custom constraints:** Integrate custom validation logic with Symfony's Validator system. - 💬 **Translations support:** Translate validation error messages into multiple languages. ## Table of Contents @@ -32,7 +35,7 @@ offering an easy-to-use and intuitive API to validate user input or other data i ## Requirements -- PHP 8.2 or higher. +- PHP 8.4 or higher. ## Installation @@ -60,7 +63,7 @@ if ($errors->count() > 0) { } ``` -Constraints autocompletion is available in IDEs like PhpStorm. +Constraint autocompletion is available in IDEs like PhpStorm. The method names match Symfony constraints but with a lowercase first letter: - `NotBlank` => `notBlank` @@ -124,10 +127,10 @@ try { Validator::notBlank()->email()->assert($email); } catch (ValidationFailedException $exception) { - // exception message will always be the first error thrown + // the exception message will always be the first error thrown $message = $exception->getMessage(); // value that failed validation - $value = $exception->getInvalidValue(); + $invalidValue = $exception->getInvalidValue(); // get access to all errors // returns a ConstraintViolationList object like in the validate method $errors = $exception->getViolations(); @@ -177,7 +180,7 @@ and keeps the fluent-style validation: ```php use ProgrammatorDev\FluentValidator\Validator; -// validate that array should have at least one value +// validate that the array should have at least one value // and each value should be between 0 and 100 $errors = Validator::count(min: 1) ->all(Validator::range(min: 0, max: 100)->toArray()) diff --git a/src/Validator.php b/src/Validator.php index a108405..f3edab4 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -45,7 +45,7 @@ public function __call(string $constraintName, array $arguments = []): self return $this; } - public function validate(mixed $value, ?string $name = null, string|GroupSequence|array|null $groups = null): ConstraintViolationListInterface + public function validate(mixed $value, ?string $name = null, array|null|string|GroupSequence $groups = null): ConstraintViolationListInterface { $builder = Validation::createValidatorBuilder(); @@ -64,7 +64,7 @@ public function validate(mixed $value, ?string $name = null, string|GroupSequenc return $context->getViolations(); } - public function assert(mixed $value, ?string $name = null, string|GroupSequence|array|null $groups = null): void + public function assert(mixed $value, ?string $name = null, array|null|string|GroupSequence $groups = null): void { $violations = $this->validate($value, $name, $groups); @@ -80,7 +80,7 @@ public function assert(mixed $value, ?string $name = null, string|GroupSequence| } } - public function isValid(mixed $value, string|GroupSequence|array|null $groups = null): bool + public function isValid(mixed $value, array|null|string|GroupSequence $groups = null): bool { $violations = $this->validate($value, groups: $groups); From 25d08c270ca94ffb8dfebc763e95e2e6e857d4d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Pimp=C3=A3o?= <41913452+andrepimpao@users.noreply.github.com> Date: Mon, 8 Dec 2025 13:05:43 +0000 Subject: [PATCH 4/4] chore: update CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 45bdd60..be1f600 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: ['8.2', '8.3', '8.4'] + php: ['8.4', '8.5'] steps: - name: Checkout code