diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4438d0d..88ae920 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 with: - php-version: "8.1" + php-version: "8.2" extensions: mbstring coverage: none tools: composer:v2 @@ -31,7 +31,7 @@ jobs: - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 with: - php-version: "8.1" + php-version: "8.2" extensions: mbstring coverage: none tools: composer:v2 @@ -64,10 +64,10 @@ jobs: strategy: fail-fast: false matrix: - php: ["8.1", "8.2", "8.3", "8.4"] + php: ["8.2", "8.3", "8.4", "8.5"] deps: ["highest"] include: - - php: "8.1" + - php: "8.2" deps: "lowest" steps: - uses: actions/checkout@v4 diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 7f1a096..396d643 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -2,30 +2,44 @@ declare(strict_types=1); +/* + * Shared php-cs-fixer configuration for every InitPHP package (ADR-005). + * + * This file is identical in all repositories as `.php-cs-fixer.dist.php`. + * The only package-specific part is the two lines below; scripts/check-cs-config.sh + * ignores exactly those two lines when it compares a package with this template. + * Keep each of them on a single line. + */ +$excludeDirs = []; +$excludePaths = []; + $finder = PhpCsFixer\Finder::create() ->in([__DIR__ . '/src', __DIR__ . '/tests']) ->name('*.php'); +foreach ($excludeDirs as $excludeDir) { + $finder->exclude($excludeDir); +} + +foreach ($excludePaths as $excludePath) { + $finder->notPath($excludePath); +} + return (new PhpCsFixer\Config()) - ->setRiskyAllowed(true) + ->setRiskyAllowed(false) ->setRules([ - '@PSR12' => true, - '@PSR12:risky' => true, - '@PHP81Migration' => true, - 'array_syntax' => ['syntax' => 'short'], - 'declare_strict_types' => true, - 'native_function_invocation' => [ - 'include' => ['@compiler_optimized'], - 'scope' => 'namespaced', - 'strict' => true, - ], - 'no_unused_imports' => true, - 'ordered_imports' => [ - 'imports_order' => ['class', 'function', 'const'], + '@PER-CS' => true, + '@PHP8x2Migration' => true, + 'array_syntax' => ['syntax' => 'short'], + 'no_unused_imports' => true, + 'ordered_imports' => [ + 'imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha', ], - 'single_quote' => true, - 'trailing_comma_in_multiline' => ['elements' => ['arrays']], + 'single_quote' => true, + 'trailing_comma_in_multiline' => [ + 'elements' => ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters'], + ], ]) ->setFinder($finder) ->setCacheFile(__DIR__ . '/build/php-cs-fixer.cache'); diff --git a/CHANGELOG.md b/CHANGELOG.md index 914af2f..0e924f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Change Log +## [Unreleased] + +### Breaking + +- **Requires PHP 8.2+** (was 8.1+); `composer.json` now requires `php: ^8.2` + and CI covers PHP 8.2, 8.3, 8.4 and 8.5. + +### Changed + +- Code style moved to PER-CS (php-cs-fixer, shared `.php-cs-fixer.dist.php`); + the codebase has been reformatted accordingly. + ## 2.0.0 [2026.06.10] A breaking release focused on correctness, safety and developer experience. diff --git a/README.md b/README.md index bb13a4b..79ddcd7 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ or custom named rules, and get back localized error messages. ## Requirements -- PHP 8.1 or higher +- PHP 8.2 or higher - `ext-mbstring` ## Installation diff --git a/composer.json b/composer.json index e649736..b5a3ff1 100644 --- a/composer.json +++ b/composer.json @@ -27,13 +27,13 @@ "docs": "https://github.com/InitPHP/Validation/tree/main/docs" }, "require": { - "php": ">=8.1", + "php": "^8.2", "ext-mbstring": "*" }, "require-dev": { "phpunit/phpunit": "^9.6", "phpstan/phpstan": "^1.12 || ^2.1", - "friendsofphp/php-cs-fixer": "^3.65" + "friendsofphp/php-cs-fixer": "^3.88" }, "autoload": { "psr-4": { diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index e4fdbf5..43e1dc4 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -23,6 +23,4 @@ * Catch this interface to handle any failure that originates from * InitPHP Validation regardless of the concrete exception type. */ -interface ExceptionInterface extends Throwable -{ -} +interface ExceptionInterface extends Throwable {} diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index c1ee0aa..9ccc276 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -23,6 +23,4 @@ * Extends the SPL {@see \InvalidArgumentException} while still implementing * {@see ExceptionInterface}, so it can be caught either way. */ -class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface -{ -} +class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface {} diff --git a/src/Exception/LocaleException.php b/src/Exception/LocaleException.php index b1988ba..75436a7 100644 --- a/src/Exception/LocaleException.php +++ b/src/Exception/LocaleException.php @@ -20,6 +20,4 @@ * exist, the language file is missing, or the file does not return an array * of message templates. */ -class LocaleException extends ValidationException -{ -} +class LocaleException extends ValidationException {} diff --git a/src/Exception/ValidationException.php b/src/Exception/ValidationException.php index d9b1d8e..d1b07bb 100644 --- a/src/Exception/ValidationException.php +++ b/src/Exception/ValidationException.php @@ -23,6 +23,4 @@ * Thrown for problems detected while a validator is being configured or * executed (for example, referencing a rule that does not exist). */ -class ValidationException extends RuntimeException implements ExceptionInterface -{ -} +class ValidationException extends RuntimeException implements ExceptionInterface {} diff --git a/tests/Validation/CallableExtendTest.php b/tests/Validation/CallableExtendTest.php index d63626c..290e610 100644 --- a/tests/Validation/CallableExtendTest.php +++ b/tests/Validation/CallableExtendTest.php @@ -23,7 +23,7 @@ protected function setUp(): void public function testCallableRulePasses(): void { $this->validation->setData(['number' => 12]); - $this->validation->rule('number', static fn (int $value): bool => ($value % 2) === 0); + $this->validation->rule('number', static fn(int $value): bool => ($value % 2) === 0); $this->assertTrue($this->validation->validation()); } @@ -31,7 +31,7 @@ public function testCallableRulePasses(): void public function testCallableRuleFails(): void { $this->validation->setData(['number' => 13]); - $this->validation->rule('number', static fn (int $value): bool => ($value % 2) === 0); + $this->validation->rule('number', static fn(int $value): bool => ($value % 2) === 0); $this->assertFalse($this->validation->validation()); } @@ -54,7 +54,7 @@ public function testArrayOfMixedRules(): void $this->validation->setData(['number' => 8]); $this->validation->rule('number', [ 'integer', - static fn ($value): bool => $value > 5, + static fn($value): bool => $value > 5, ]); $this->assertTrue($this->validation->validation()); @@ -63,7 +63,7 @@ public function testArrayOfMixedRules(): void public function testExtendRegistersNamedRule(): void { $this->validation->setData(['age' => 7]); - $this->validation->extend('even', static fn (int $value): bool => ($value % 2) === 0); + $this->validation->extend('even', static fn(int $value): bool => ($value % 2) === 0); $this->validation->rule('age', 'even'); $this->assertFalse($this->validation->validation()); @@ -74,7 +74,7 @@ public function testExtendRuleReceivesArguments(): void $this->validation->setData(['value' => 10]); $this->validation->extend( 'divisible', - static fn (int $value, string $by): bool => ($value % (int) $by) === 0 + static fn(int $value, string $by): bool => ($value % (int) $by) === 0, ); $this->validation->rule('value', 'divisible(5)'); @@ -89,8 +89,8 @@ public function testExtendRegistersCustomMessage(): void $this->validation->setData(['age' => 7]); $this->validation->extend( 'even', - static fn (int $value): bool => ($value % 2) === 0, - '{field} must be an even number.' + static fn(int $value): bool => ($value % 2) === 0, + '{field} must be an even number.', ); $this->validation->rule('age', 'even'); $this->validation->validation(); @@ -100,7 +100,7 @@ public function testExtendRegistersCustomMessage(): void public function testExtensionsSurviveValidationRuns(): void { - $this->validation->extend('even', static fn (int $value): bool => ($value % 2) === 0); + $this->validation->extend('even', static fn(int $value): bool => ($value % 2) === 0); $this->validation->setData(['a' => 4])->rule('a', 'even'); $this->assertTrue($this->validation->validation()); diff --git a/tests/Validation/ErrorMessageTest.php b/tests/Validation/ErrorMessageTest.php index 9268761..e16978d 100644 --- a/tests/Validation/ErrorMessageTest.php +++ b/tests/Validation/ErrorMessageTest.php @@ -37,7 +37,7 @@ public function testPositionalArgumentPlaceholder(): void $this->assertSame( ['age must be greater than or equal to 18.'], - $this->validation->getError() + $this->validation->getError(), ); } @@ -62,7 +62,7 @@ public function testArgumentValuesAreNotPassedThroughLabels(): void $this->assertSame( ['mail must be an e-mail at gmail.com.'], - $this->validation->getError() + $this->validation->getError(), ); } @@ -74,7 +74,7 @@ public function testCustomMessageOverridesDefaultAndInterpolates(): void $this->assertSame( ['age is too small (min 18).'], - $this->validation->getError() + $this->validation->getError(), ); } @@ -83,26 +83,26 @@ public function testCallableFailureUsesCustomMessage(): void $this->validation->setData(['number' => 13]); $this->validation->rule( 'number', - static fn (int $value): bool => ($value % 2) === 0, - '{field} must be an even number.' + static fn(int $value): bool => ($value % 2) === 0, + '{field} must be an even number.', ); $this->validation->validation(); $this->assertSame( ['number must be an even number.'], - $this->validation->getError() + $this->validation->getError(), ); } public function testCallableFailureFallsBackToDefaultMessage(): void { $this->validation->setData(['number' => 13]); - $this->validation->rule('number', static fn ($value): bool => false); + $this->validation->rule('number', static fn($value): bool => false); $this->validation->validation(); $this->assertSame( ['The number value is not valid.'], - $this->validation->getError() + $this->validation->getError(), ); } diff --git a/tests/Validation/LocaleTest.php b/tests/Validation/LocaleTest.php index dde9c3f..6be893e 100644 --- a/tests/Validation/LocaleTest.php +++ b/tests/Validation/LocaleTest.php @@ -32,7 +32,7 @@ public function testEnglishAgainMessageResolves(): void $this->assertSame( ['password must be the same as confirm.'], - $this->validation->getError() + $this->validation->getError(), ); }