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