Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
52 changes: 31 additions & 21 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
},
"minimum-stability": "stable",
"require": {
"php": ">=8.1",
"php": "^8.2",
"ext-json": "*",
"initphp/parameterbag": "^2.0",
"initphp/validation": "^2.0"
},
"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": {
Expand Down
14 changes: 7 additions & 7 deletions src/Inputs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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,
);
}

Expand All @@ -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,
);
}

Expand Down Expand Up @@ -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,
);
}

Expand All @@ -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,
);
}

Expand Down Expand Up @@ -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,
);
}

Expand All @@ -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,
);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/ValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)']),
);
}

Expand All @@ -87,15 +87,15 @@ public function testCrossFieldRuleFails(): void
], []);

self::assertNull(
$input->post('password', null, ['required', 'again(password_retype)'])
$input->post('password', null, ['required', 'again(password_retype)']),
);
}

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]));
}
Expand Down
Loading