Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| Password | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| normalize | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getExceptionClass | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| validateRules | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | // ╔════════════════════════════════════════════════════════════╗ |
| 4 | // ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║ |
| 5 | // ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com> ║ |
| 6 | // ╚════════════════════════════════════════════════════════════╝ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | namespace AppDemo\User\Domain; |
| 11 | |
| 12 | use AppDemo\User\Domain\Exception\InvalidPasswordException; |
| 13 | use Assert\Assert; |
| 14 | use Override; |
| 15 | use Phexium\Domain\AbstractStringValueObject; |
| 16 | use Phexium\Domain\ValueObjectInterface; |
| 17 | |
| 18 | final readonly class Password extends AbstractStringValueObject implements ValueObjectInterface |
| 19 | { |
| 20 | #[Override] |
| 21 | protected function normalize(string $value): string |
| 22 | { |
| 23 | return $value; |
| 24 | } |
| 25 | |
| 26 | #[Override] |
| 27 | protected static function getExceptionClass(): callable |
| 28 | { |
| 29 | return InvalidPasswordException::whenValidationFailed(...); |
| 30 | } |
| 31 | |
| 32 | #[Override] |
| 33 | protected function validateRules(string $value): void |
| 34 | { |
| 35 | Assert::that($value) |
| 36 | ->notEmpty('Password cannot be empty') |
| 37 | ->minLength(8, 'Password must be at least 8 characters long') |
| 38 | ->maxLength(255, 'Password cannot exceed 255 characters') |
| 39 | ; |
| 40 | } |
| 41 | } |