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: 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: 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
46 changes: 30 additions & 16 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 1 addition & 3 deletions src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
4 changes: 1 addition & 3 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
4 changes: 1 addition & 3 deletions src/Exception/LocaleException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
4 changes: 1 addition & 3 deletions src/Exception/ValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
16 changes: 8 additions & 8 deletions tests/Validation/CallableExtendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ 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());
}

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());
}
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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)');
Expand All @@ -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();
Expand All @@ -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());
Expand Down
16 changes: 8 additions & 8 deletions tests/Validation/ErrorMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}

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

Expand All @@ -74,7 +74,7 @@ public function testCustomMessageOverridesDefaultAndInterpolates(): void

$this->assertSame(
['age is too small (min 18).'],
$this->validation->getError()
$this->validation->getError(),
);
}

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

Expand Down
2 changes: 1 addition & 1 deletion tests/Validation/LocaleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testEnglishAgainMessageResolves(): void

$this->assertSame(
['password must be the same as confirm.'],
$this->validation->getError()
$this->validation->getError(),
);
}

Expand Down
Loading