diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 73fce7a..9c5a640 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: json, 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: json, 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 e4368e9..396d643 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -2,34 +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, - '@PHP81Migration' => true, - 'declare_strict_types' => true, - 'array_syntax' => ['syntax' => 'short'], - 'no_unused_imports' => true, - 'ordered_imports' => [ + '@PER-CS' => true, + '@PHP8x2Migration' => true, + 'array_syntax' => ['syntax' => 'short'], + 'no_unused_imports' => true, + 'ordered_imports' => [ + 'imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha', - 'imports_order' => ['class', 'function', 'const'], ], - 'single_quote' => true, - 'trailing_comma_in_multiline' => true, - 'no_trailing_whitespace' => true, - 'no_whitespace_in_blank_line' => true, - 'blank_line_after_opening_tag' => true, - 'blank_line_before_statement' => ['statements' => ['return']], - 'method_chaining_indentation' => true, - 'native_function_invocation' => false, - 'phpdoc_align' => ['align' => 'vertical'], - 'phpdoc_separation' => true, - 'phpdoc_trim' => true, - 'no_superfluous_phpdoc_tags' => false, + 'single_quote' => true, + 'trailing_comma_in_multiline' => [ + 'elements' => ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters'], + ], ]) ->setFinder($finder) - ->setCacheFile(__DIR__ . '/.php-cs-fixer.cache'); + ->setCacheFile(__DIR__ . '/build/php-cs-fixer.cache'); diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e5b3b59 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,13 @@ +# Changelog + +All notable changes to **initphp/input** will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Changed (breaking) + +- **Requires PHP `^8.2`.** Support for PHP 8.1 is dropped; CI now runs PHP 8.2, 8.3, 8.4 and 8.5. +- **Coding standard moved to PER-CS** through the shared `.php-cs-fixer.dist.php`; the whole code base was reformatted. diff --git a/README.md b/README.md index 0150fab..ad60be5 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ optional validation, behind one small API. ## Requirements -- PHP 8.1 or later +- PHP 8.2 or later - [initphp/parameterbag](https://github.com/InitPHP/ParameterBag) `^2.0` - [initphp/validation](https://github.com/InitPHP/Validation) `^2.0` - `ext-json` diff --git a/composer.json b/composer.json index ea3e2f2..ca4dccc 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ }, "minimum-stability": "stable", "require": { - "php": ">=8.1", + "php": "^8.2", "ext-json": "*", "initphp/parameterbag": "^2.0", "initphp/validation": "^2.0" @@ -36,7 +36,7 @@ "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/Inputs.php b/src/Inputs.php index aeb4f18..ef4e579 100644 --- a/src/Inputs.php +++ b/src/Inputs.php @@ -82,7 +82,7 @@ public function __construct( ?array $get = null, ?array $post = null, ?array $raw = null, - ?Validation $validation = null + ?Validation $validation = null, ) { $options = ['isMulti' => false]; $this->bags = [ @@ -142,7 +142,7 @@ public function getPostRaw(string $key, mixed $default = null, ?array $validatio [self::SOURCE_GET, self::SOURCE_POST, self::SOURCE_RAW], $key, $default, - $validation + $validation, ); } @@ -155,7 +155,7 @@ public function getRawPost(string $key, mixed $default = null, ?array $validatio [self::SOURCE_GET, self::SOURCE_RAW, self::SOURCE_POST], $key, $default, - $validation + $validation, ); } @@ -184,7 +184,7 @@ public function postGetRaw(string $key, mixed $default = null, ?array $validatio [self::SOURCE_POST, self::SOURCE_GET, self::SOURCE_RAW], $key, $default, - $validation + $validation, ); } @@ -197,7 +197,7 @@ public function postRawGet(string $key, mixed $default = null, ?array $validatio [self::SOURCE_POST, self::SOURCE_RAW, self::SOURCE_GET], $key, $default, - $validation + $validation, ); } @@ -226,7 +226,7 @@ public function rawGetPost(string $key, mixed $default = null, ?array $validatio [self::SOURCE_RAW, self::SOURCE_GET, self::SOURCE_POST], $key, $default, - $validation + $validation, ); } @@ -239,7 +239,7 @@ public function rawPostGet(string $key, mixed $default = null, ?array $validatio [self::SOURCE_RAW, self::SOURCE_POST, self::SOURCE_GET], $key, $default, - $validation + $validation, ); } diff --git a/tests/ValidationTest.php b/tests/ValidationTest.php index 9734661..880000e 100644 --- a/tests/ValidationTest.php +++ b/tests/ValidationTest.php @@ -75,7 +75,7 @@ public function testCrossFieldRulePasses(): void self::assertSame( 'secret', - $input->post('password', null, ['required', 'again(password_retype)']) + $input->post('password', null, ['required', 'again(password_retype)']), ); } @@ -87,7 +87,7 @@ public function testCrossFieldRuleFails(): void ], []); self::assertNull( - $input->post('password', null, ['required', 'again(password_retype)']) + $input->post('password', null, ['required', 'again(password_retype)']), ); } @@ -95,7 +95,7 @@ public function testCallableRuleIsSupported(): void { $input = new Inputs(['age' => '20'], [], []); - $even = static fn ($value): bool => is_numeric($value) && (int) $value % 2 === 0; + $even = static fn($value): bool => is_numeric($value) && (int) $value % 2 === 0; self::assertSame('20', $input->get('age', null, [$even])); }