From 2ddde79be0dca008637dbf684749b5500ec6c477 Mon Sep 17 00:00:00 2001 From: przemyslaw-przylucki Date: Thu, 30 May 2024 22:11:01 +0200 Subject: [PATCH] QA --- src/Support/LanguageHelper.php | 15 ++++++----- .../Exceptions/ValidationException.php | 2 +- src/Validation/Rules/Password.php | 4 ++- .../Validation/ValidationExceptionTest.php | 25 +++++++++---------- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/Support/LanguageHelper.php b/src/Support/LanguageHelper.php index bfc7aa2..99fc1cf 100644 --- a/src/Support/LanguageHelper.php +++ b/src/Support/LanguageHelper.php @@ -6,16 +6,19 @@ final class LanguageHelper { - - public static function join(array $strings): string + /** + * @param string[] $parts + * + * @return string + */ + public static function join(array $parts): string { - $last = array_pop($strings); + $last = array_pop($parts); - if ($strings) { - return implode(', ', $strings) . ' ' . 'and' . ' ' . $last; + if ($parts) { + return implode(', ', $parts) . ' ' . 'and' . ' ' . $last; } return $last; } - } diff --git a/src/Validation/Exceptions/ValidationException.php b/src/Validation/Exceptions/ValidationException.php index 5917d57..3fa6b1d 100644 --- a/src/Validation/Exceptions/ValidationException.php +++ b/src/Validation/Exceptions/ValidationException.php @@ -5,9 +5,9 @@ namespace Tempest\Validation\Exceptions; use Exception; -use Tempest\Validation\Rule; use Tempest\Support\ArrayHelper; use Tempest\Support\LanguageHelper; +use Tempest\Validation\Rule; final class ValidationException extends Exception { diff --git a/src/Validation/Rules/Password.php b/src/Validation/Rules/Password.php index 1f6cc79..0aa9af5 100644 --- a/src/Validation/Rules/Password.php +++ b/src/Validation/Rules/Password.php @@ -6,7 +6,6 @@ use Attribute; use Tempest\Validation\Rule; -use Tempest\Support\LanguageHelper; #[Attribute] final readonly class Password implements Rule @@ -52,6 +51,9 @@ public function isValid(mixed $value): bool return true; } + /** + * @return string[] + */ public function message(): array { $messages = ["Value should contain at least {$this->min} characters"]; diff --git a/tests/Unit/Validation/ValidationExceptionTest.php b/tests/Unit/Validation/ValidationExceptionTest.php index 4333428..72e324e 100644 --- a/tests/Unit/Validation/ValidationExceptionTest.php +++ b/tests/Unit/Validation/ValidationExceptionTest.php @@ -4,14 +4,17 @@ namespace Tests\Tempest\Unit\Validation; -use stdClass; -use Tempest\Validation\Rule; use PHPUnit\Framework\TestCase; +use stdClass; use Tempest\Validation\Exceptions\ValidationException; +use Tempest\Validation\Rule; +/** + * @internal + * @small + */ final class ValidationExceptionTest extends TestCase { - public function test_exception_message(): void { $this->expectException(ValidationException::class); @@ -20,8 +23,7 @@ public function test_exception_message(): void throw new ValidationException(new stdClass(), [ 'email' => [ - new class implements Rule { - + new class () implements Rule { public function isValid(mixed $value): bool { return false; @@ -31,8 +33,8 @@ public function message(): string|array { return 'Value should be a valid email address'; } - } - ] + }, + ], ]); } @@ -45,8 +47,7 @@ public function test_exception_message_with_multiple_messages(): void throw new ValidationException(new stdClass(), [ 'email' => [ - new class implements Rule { - + new class () implements Rule { public function isValid(mixed $value): bool { return false; @@ -57,8 +58,7 @@ public function message(): string|array return 'Value should be a valid email address'; } }, - new class implements Rule { - + new class () implements Rule { public function isValid(mixed $value): bool { return false; @@ -72,8 +72,7 @@ public function message(): string|array 'the new gods from the future', ]; } - }] + }], ]); } - }