Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
6 / 6 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
UserWithAddress | |
100.00% |
6 / 6 |
|
100.00% |
6 / 6 |
7 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getAddress | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setPassword | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
hasPassword | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
verifyAuthentication | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | namespace Apie\Fixtures\Entities; |
3 | |
4 | use Apie\Core\Attributes\Internal; |
5 | use Apie\Core\Attributes\RemovalCheck; |
6 | use Apie\Core\Attributes\SearchFilterOption; |
7 | use Apie\Core\Attributes\StaticCheck; |
8 | use Apie\Core\Entities\EntityInterface; |
9 | use Apie\Fixtures\Identifiers\UserWithAddressIdentifier; |
10 | use Apie\Fixtures\ValueObjects\AddressWithZipcodeCheck; |
11 | use Apie\Fixtures\ValueObjects\EncryptedPassword; |
12 | use Apie\Fixtures\ValueObjects\Password; |
13 | |
14 | #[RemovalCheck(new StaticCheck())] |
15 | class UserWithAddress implements EntityInterface |
16 | { |
17 | private UserWithAddressIdentifier $id; |
18 | |
19 | private ?EncryptedPassword $password = null; |
20 | |
21 | public function __construct(private AddressWithZipcodeCheck $address, ?UserWithAddressIdentifier $id = null) |
22 | { |
23 | $this->id = $id ?? UserWithAddressIdentifier::createRandom(); |
24 | } |
25 | |
26 | public function getId(): UserWithAddressIdentifier |
27 | { |
28 | return $this->id; |
29 | } |
30 | |
31 | public function getAddress(): AddressWithZipcodeCheck |
32 | { |
33 | return $this->address; |
34 | } |
35 | |
36 | public function setPassword(Password $password) |
37 | { |
38 | $this->password = EncryptedPassword::fromUnencryptedPassword($password); |
39 | } |
40 | |
41 | #[Internal()] |
42 | #[SearchFilterOption(enabled: false)] |
43 | public function hasPassword(): bool |
44 | { |
45 | return $this->password !== null; |
46 | } |
47 | |
48 | public function verifyAuthentication(string $username, string $password): bool |
49 | { |
50 | return $this->id->toNative() === $username && $this->password->verifyUnencryptedPassword($password); |
51 | } |
52 | } |