From 8cafa3f2981e585686663af2b8310e80ff967d95 Mon Sep 17 00:00:00 2001 From: Alexandre Gomes Gaigalas Date: Fri, 17 Feb 2023 03:12:57 -0300 Subject: [PATCH] Drop PHP 7.4 support --- .github/workflows/continuous-integration.yml | 5 +- CHANGELOG.md | 12 +++ composer.json | 7 +- docs/feature-guide.md | 8 -- docs/rules/Sf.md | 27 ------ library/ChainedValidator.php | 4 - library/Exceptions/SfException.php | 29 ------ library/Rules/Sf.php | 96 -------------------- library/StaticValidator.php | 4 - tests/integration/rules/sf.phpt | 60 ------------ tests/unit/Rules/SfTest.php | 72 --------------- 11 files changed, 17 insertions(+), 307 deletions(-) delete mode 100644 docs/rules/Sf.md delete mode 100644 library/Exceptions/SfException.php delete mode 100644 library/Rules/Sf.php delete mode 100644 tests/integration/rules/sf.phpt delete mode 100644 tests/unit/Rules/SfTest.php diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 6a2a3672..336acada 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -19,7 +19,6 @@ jobs: strategy: matrix: php-version: - - "7.4" - "8.0" - "8.1" - "8.2" @@ -63,7 +62,7 @@ jobs: - name: Install PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: 8.0 coverage: pcov extensions: uopz tools: pecl @@ -97,7 +96,7 @@ jobs: - name: Install PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: 8.0 coverage: none - name: Install dependencies diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c1b50e0..7b26191f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changes in Respect\Validation 2.x +## 2.3 + +Versioning Changes: + + - Dropped support for PHP 7.4. + - Updated dev dependencies + +Deprecations: + + - Symfony façade validators are no longer supported and were + removed. + ## 2.2.4 Meta: diff --git a/composer.json b/composer.json index b56e5053..6a7504ef 100644 --- a/composer.json +++ b/composer.json @@ -18,13 +18,13 @@ } }, "require": { - "php": "^7.4 || ^8.0 || ^8.1 || ^8.2", + "php": "^8.0 || ^8.1 || ^8.2", "respect/stringifier": "^0.2.0", "symfony/polyfill-mbstring": "^1.2" }, "require-dev": { "egulias/email-validator": "^3.0", - "malukenho/docheader": "^0.1", + "malukenho/docheader": "^1.0", "mikey179/vfsstream": "^1.6", "phpstan/phpstan": "^1.9", "phpstan/phpstan-deprecation-rules": "^1.1", @@ -32,8 +32,7 @@ "phpunit/phpunit": "^9.6", "psr/http-message": "^1.0", "respect/coding-standard": "^3.0", - "squizlabs/php_codesniffer": "^3.7", - "symfony/validator": "^3.0||^4.0||^5.0" + "squizlabs/php_codesniffer": "^3.7" }, "suggest": { "ext-bcmath": "Arbitrary Precision Mathematics", diff --git a/docs/feature-guide.md b/docs/feature-guide.md index 4be1a2ce..7e0eadcd 100644 --- a/docs/feature-guide.md +++ b/docs/feature-guide.md @@ -237,14 +237,6 @@ is the same as the input. You can customize a validator name using: v::dateTime('Y-m-d')->between('1980-02-02', 'now')->setName('Member Since'); ``` -## Symfony validators - -It is also possible to reuse validators from Symfony if they are installed: - -```php -$timeValidator = v::sf('Time')->assert('22:00:01'); -``` - ## Validation methods We've seen `validate()` that returns true or false and `assert()` that throws a complete diff --git a/docs/rules/Sf.md b/docs/rules/Sf.md deleted file mode 100644 index 815acb0a..00000000 --- a/docs/rules/Sf.md +++ /dev/null @@ -1,27 +0,0 @@ -# Sf - -- `Sf(Constraint $constraint)` -- `Sf(Constraint $constraint, ValidatorInterface $validator)` - -Validate the input with a Symfony Validator (>=4.0 or >=3.0) Constraint. - -```php -use Symfony\Component\Validator\Constraint\Iban; - -v::sf(new Iban())->validate('NL39 RABO 0300 0652 64'); // true -``` - -This rule will keep all the messages returned from Symfony. - -## Categorization - -- Integrations - -## Changelog - -Version | Description ---------|------------- - 2.0.0 | Do not create constraints anymore - 2.0.0 | Upgraded support to version >=4.0 or >=3.0 of Symfony Validator - 0.3.9 | Created - diff --git a/library/ChainedValidator.php b/library/ChainedValidator.php index fe989e3c..c0c4b3e8 100644 --- a/library/ChainedValidator.php +++ b/library/ChainedValidator.php @@ -11,8 +11,6 @@ namespace Respect\Validation; use finfo; use Respect\Validation\Rules\Key; -use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\Validator\ValidatorInterface as SymfonyValidator; interface ChainedValidator extends Validatable { @@ -316,8 +314,6 @@ interface ChainedValidator extends Validatable public function scalarVal(): ChainedValidator; - public function sf(Constraint $constraint, ?SymfonyValidator $validator = null): ChainedValidator; - public function size(?string $minSize = null, ?string $maxSize = null): ChainedValidator; public function slug(): ChainedValidator; diff --git a/library/Exceptions/SfException.php b/library/Exceptions/SfException.php deleted file mode 100644 index b40d992e..00000000 --- a/library/Exceptions/SfException.php +++ /dev/null @@ -1,29 +0,0 @@ - - * SPDX-License-Identifier: MIT - */ - -declare(strict_types=1); - -namespace Respect\Validation\Exceptions; - -/** - * @author Alexandre Gomes Gaigalas - * @author Henrique Moody - */ -final class SfException extends ValidationException -{ - /** - * {@inheritDoc} - */ - protected $defaultTemplates = [ - self::MODE_DEFAULT => [ - self::STANDARD => '{{name}} must be valid for {{constraint}}', - ], - self::MODE_NEGATIVE => [ - self::STANDARD => '{{name}} must not be valid for {{constraint}}', - ], - ]; -} diff --git a/library/Rules/Sf.php b/library/Rules/Sf.php deleted file mode 100644 index f018ed3e..00000000 --- a/library/Rules/Sf.php +++ /dev/null @@ -1,96 +0,0 @@ - - * SPDX-License-Identifier: MIT - */ - -declare(strict_types=1); - -namespace Respect\Validation\Rules; - -use Respect\Validation\Exceptions\SfException; -use Respect\Validation\Exceptions\ValidationException; -use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\ConstraintViolationList; -use Symfony\Component\Validator\Validation; -use Symfony\Component\Validator\Validator\ValidatorInterface; - -use function trim; - -/** - * Validate the input with a Symfony Validator (>=4.0 or >=3.0) Constraint. - * - * @author Alexandre Gomes Gaigalas - * @author Augusto Pascutti - * @author Henrique Moody - * @author Hugo Hamon - */ -final class Sf extends AbstractRule -{ - /** - * @var Constraint - */ - private $constraint; - - /** - * @var ValidatorInterface - */ - private $validator; - - /** - * Initializes the rule with the Constraint and the Validator. - * - * In the the Validator is not defined, tries to create one. - */ - public function __construct(Constraint $constraint, ?ValidatorInterface $validator = null) - { - $this->constraint = $constraint; - $this->validator = $validator ?: Validation::createValidator(); - } - - /** - * {@inheritDoc} - */ - public function assert($input): void - { - /** @var ConstraintViolationList $violations */ - $violations = $this->validator->validate($input, $this->constraint); - if ($violations->count() === 0) { - return; - } - - if ($violations->count() === 1) { - throw $this->reportError($input, ['violations' => $violations[0]->getMessage()]); - } - - throw $this->reportError($input, ['violations' => trim($violations->__toString())]); - } - - /** - * {@inheritDoc} - */ - public function reportError($input, array $extraParams = []): ValidationException - { - $exception = parent::reportError($input, $extraParams); - if (isset($extraParams['violations'])) { - $exception->updateTemplate($extraParams['violations']); - } - - return $exception; - } - - /** - * {@inheritDoc} - */ - public function validate($input): bool - { - try { - $this->assert($input); - } catch (SfException $exception) { - return false; - } - - return true; - } -} diff --git a/library/StaticValidator.php b/library/StaticValidator.php index e313d1e3..8e447606 100644 --- a/library/StaticValidator.php +++ b/library/StaticValidator.php @@ -11,8 +11,6 @@ namespace Respect\Validation; use finfo; use Respect\Validation\Rules\Key; -use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\Validator\ValidatorInterface as SymfonyValidator; interface StaticValidator { @@ -316,8 +314,6 @@ interface StaticValidator public static function scalarVal(): ChainedValidator; - public static function sf(Constraint $constraint, ?SymfonyValidator $validator = null): ChainedValidator; - public static function size(?string $minSize = null, ?string $maxSize = null): ChainedValidator; public static function slug(): ChainedValidator; diff --git a/tests/integration/rules/sf.phpt b/tests/integration/rules/sf.phpt deleted file mode 100644 index c6a3038f..00000000 --- a/tests/integration/rules/sf.phpt +++ /dev/null @@ -1,60 +0,0 @@ ---CREDITS-- -Henrique Moody ---FILE-- -check('something'); -} catch (SfException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::sf(new IsNull()))->check(null); -} catch (SfException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::sf(new Email())->assert('not-null'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::sf(new Email()))->assert('example@example.com'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::sf( - new Collection([ - 'first' => new IsNull(), - 'second' => new Email(), - ]) - )->check(['second' => 'not-email']); -} catch (SfException $exception) { - echo $exception->getMessage(); -} -?> ---EXPECTF-- -This value should be null. -`NULL` must not be valid for `[object] (Symfony\Component\Validator\Constraints\IsNull: { %s })` -- This value is not a valid email address. -- "example@example.com" must not be valid for `[object] (Symfony\Component\Validator\Constraints\Email: { %s })` -Array[first]: - This field is missing. (code %s) -Array[second]: - This value is not a valid email address. (code %s) diff --git a/tests/unit/Rules/SfTest.php b/tests/unit/Rules/SfTest.php deleted file mode 100644 index dc02fb7a..00000000 --- a/tests/unit/Rules/SfTest.php +++ /dev/null @@ -1,72 +0,0 @@ - - * SPDX-License-Identifier: MIT - */ - -declare(strict_types=1); - -namespace Respect\Validation\Rules; - -use Respect\Validation\Test\TestCase; -use stdClass; -use Symfony\Component\Validator\Constraints\IsFalse; -use Symfony\Component\Validator\Constraints\IsNull; -use Symfony\Component\Validator\Validation; -use Symfony\Component\Validator\Validator\TraceableValidator; - -use function class_exists; - -/** - * @group rule - * - * @covers \Respect\Validation\Rules\Sf - * - * @author Augusto Pascutti - * @author Gabriel Caruso - * @author Henrique Moody - */ -final class SfTest extends TestCase -{ - /** - * @test - */ - public function itShouldValidateWithDefinedConstraintAndValidator(): void - { - $sut = new Sf(new IsNull()); - - self::assertTrue($sut->validate(null)); - } - - /** - * @test - */ - public function itShouldInvalidateWithDefinedConstraintAndValidator(): void - { - $sut = new Sf(new IsFalse()); - - self::assertFalse($sut->validate(true)); - } - - /** - * @test - */ - public function itShouldUseTheDefinedValidatorToValidate(): void - { - if (!class_exists(TraceableValidator::class)) { - self::markTestSkipped( - 'The current version of Symfony Validator does not have ' . TraceableValidator::class - ); - } - - $input = new stdClass(); - - $validator = new TraceableValidator(Validation::createValidator()); - - $sut = new Sf(new IsNull(), $validator); - $sut->validate($input); - - self::assertSame($input, $validator->getCollectedData()[0]['context']['value']); - } -}