Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
66.67% covered (warning)
66.67%
4 / 6
50.00% covered (danger)
50.00%
2 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
EncryptedPassword
66.67% covered (warning)
66.67%
4 / 6
50.00% covered (danger)
50.00%
2 / 4
4.59
0.00% covered (danger)
0.00%
0 / 1
 fromUnencryptedPassword
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 verifyUnencryptedPassword
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getIndexes
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 createRandom
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2namespace Apie\Fixtures\ValueObjects;
3
4use Apie\Core\Attributes\FakeMethod;
5use Apie\Core\Attributes\ProvideIndex;
6use Apie\Core\ValueObjects\Interfaces\StringValueObjectInterface;
7use Apie\Core\ValueObjects\IsStringValueObject;
8use Faker\Generator;
9use Stringable;
10
11#[FakeMethod('createRandom')]
12#[ProvideIndex('getIndexes')]
13final 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}