Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
66.67% |
4 / 6 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| EncryptedPassword | |
66.67% |
4 / 6 |
|
50.00% |
2 / 4 |
4.59 | |
0.00% |
0 / 1 |
| fromUnencryptedPassword | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| verifyUnencryptedPassword | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getIndexes | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| createRandom | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\Fixtures\ValueObjects; |
| 3 | |
| 4 | use Apie\Core\Attributes\FakeMethod; |
| 5 | use Apie\Core\Attributes\ProvideIndex; |
| 6 | use Apie\Core\ValueObjects\Interfaces\StringValueObjectInterface; |
| 7 | use Apie\Core\ValueObjects\IsStringValueObject; |
| 8 | use Faker\Generator; |
| 9 | use Stringable; |
| 10 | |
| 11 | #[FakeMethod('createRandom')] |
| 12 | #[ProvideIndex('getIndexes')] |
| 13 | final class EncryptedPassword implements StringValueObjectInterface |
| 14 | { |
| 15 | use IsStringValueObject; |
| 16 | |
| 17 | public static function fromUnencryptedPassword(Stringable|string $password): self |
| 18 | { |
| 19 | $password = (string) $password; |
| 20 | return new self(password_hash($password, null)); |
| 21 | } |
| 22 | |
| 23 | public function verifyUnencryptedPassword(Stringable|string $password): bool |
| 24 | { |
| 25 | $password = (string) $password; |
| 26 | return password_verify($password, $this->internal); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @return array<string, int> |
| 31 | */ |
| 32 | public static function getIndexes(): array |
| 33 | { |
| 34 | return []; |
| 35 | } |
| 36 | |
| 37 | public static function createRandom(Generator $generator): self |
| 38 | { |
| 39 | return self::fromUnencryptedPassword($generator->password(6, 42)); |
| 40 | } |
| 41 | } |