Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
91.67% |
11 / 12 |
|
91.67% |
11 / 12 |
|
87.50% |
7 / 8 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| DefaultIdentityService | |
91.67% |
11 / 12 |
|
91.67% |
11 / 12 |
|
87.50% |
7 / 8 |
|
75.00% |
3 / 4 |
8.12 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createIdentity | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| changeEmail | |
80.00% |
4 / 5 |
|
80.00% |
4 / 5 |
|
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
3.33 | |||
| complete | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Auth\Domain\Service; |
| 4 | |
| 5 | use App\Auth\Domain\Model\Identity; |
| 6 | use App\Auth\Domain\Port\Driven\EmailAvailabilityChecker; |
| 7 | use App\Auth\Domain\Port\Driven\IdentityAvailabilityChecker; |
| 8 | use App\Auth\Domain\Port\Driven\PasswordHasher; |
| 9 | use App\Shared\Domain\Exception\EntityAlreadyExistsException; |
| 10 | use App\Shared\Domain\Model\EntityId; |
| 11 | |
| 12 | readonly class DefaultIdentityService implements IdentityService |
| 13 | { |
| 14 | public function __construct( |
| 15 | private PasswordHasher $passwordHasher, |
| 16 | private IdentityAvailabilityChecker $identityAvailabilityChecker, |
| 17 | private EmailAvailabilityChecker $emailAvailabilityChecker |
| 18 | ) { |
| 19 | } |
| 20 | |
| 21 | public function createIdentity(string $email, string $username, string $password): ?Identity |
| 22 | { |
| 23 | if (!$this->identityAvailabilityChecker->isIdentityAvailable($email, $username)) { |
| 24 | throw new EntityAlreadyExistsException('Identity already exists'); |
| 25 | } |
| 26 | return Identity::create(EntityId::generate(), $email, $username, $this->passwordHasher->hash($password)); |
| 27 | } |
| 28 | |
| 29 | public function changeEmail(Identity $identity, string $email): Identity |
| 30 | { |
| 31 | if ($identity->getEmail() === $email) { |
| 32 | return $identity; |
| 33 | } |
| 34 | |
| 35 | if (!$this->emailAvailabilityChecker->isEmailAvailable($email)) { |
| 36 | throw new EntityAlreadyExistsException('Email is taken'); |
| 37 | } |
| 38 | |
| 39 | return $identity->changeEmail($email); |
| 40 | } |
| 41 | |
| 42 | public function complete(Identity $identity): Identity |
| 43 | { |
| 44 | if ($identity->isComplete()) { |
| 45 | return $identity; |
| 46 | } |
| 47 | |
| 48 | return $identity->complete(); |
| 49 | } |
| 50 | } |
Below are the source code lines that represent each code path as identified by Xdebug. Please note a path is not
necessarily coterminous with a line, a line may contain multiple paths and therefore show up more than once.
Please also be aware that some paths may include implicit rather than explicit branches, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 14 | public function __construct( |
| 15 | private PasswordHasher $passwordHasher, |
| 16 | private IdentityAvailabilityChecker $identityAvailabilityChecker, |
| 17 | private EmailAvailabilityChecker $emailAvailabilityChecker |
| 18 | ) { |
| 19 | } |
| 29 | public function changeEmail(Identity $identity, string $email): Identity |
| 30 | { |
| 31 | if ($identity->getEmail() === $email) { |
| 32 | return $identity; |
| 29 | public function changeEmail(Identity $identity, string $email): Identity |
| 30 | { |
| 31 | if ($identity->getEmail() === $email) { |
| 35 | if (!$this->emailAvailabilityChecker->isEmailAvailable($email)) { |
| 36 | throw new EntityAlreadyExistsException('Email is taken'); |
| 29 | public function changeEmail(Identity $identity, string $email): Identity |
| 30 | { |
| 31 | if ($identity->getEmail() === $email) { |
| 35 | if (!$this->emailAvailabilityChecker->isEmailAvailable($email)) { |
| 39 | return $identity->changeEmail($email); |
| 40 | } |
| 42 | public function complete(Identity $identity): Identity |
| 43 | { |
| 44 | if ($identity->isComplete()) { |
| 45 | return $identity; |
| 42 | public function complete(Identity $identity): Identity |
| 43 | { |
| 44 | if ($identity->isComplete()) { |
| 48 | return $identity->complete(); |
| 49 | } |
| 21 | public function createIdentity(string $email, string $username, string $password): ?Identity |
| 22 | { |
| 23 | if (!$this->identityAvailabilityChecker->isIdentityAvailable($email, $username)) { |
| 24 | throw new EntityAlreadyExistsException('Identity already exists'); |
| 21 | public function createIdentity(string $email, string $username, string $password): ?Identity |
| 22 | { |
| 23 | if (!$this->identityAvailabilityChecker->isIdentityAvailable($email, $username)) { |
| 26 | return Identity::create(EntityId::generate(), $email, $username, $this->passwordHasher->hash($password)); |
| 27 | } |
| 3 | namespace App\Auth\Domain\Service; |
| 4 | |
| 5 | use App\Auth\Domain\Model\Identity; |
| 6 | use App\Auth\Domain\Port\Driven\EmailAvailabilityChecker; |
| 7 | use App\Auth\Domain\Port\Driven\IdentityAvailabilityChecker; |
| 8 | use App\Auth\Domain\Port\Driven\PasswordHasher; |
| 9 | use App\Shared\Domain\Exception\EntityAlreadyExistsException; |
| 10 | use App\Shared\Domain\Model\EntityId; |
| 11 | |
| 12 | readonly class DefaultIdentityService implements IdentityService |
| 13 | { |
| 14 | public function __construct( |
| 15 | private PasswordHasher $passwordHasher, |
| 16 | private IdentityAvailabilityChecker $identityAvailabilityChecker, |
| 17 | private EmailAvailabilityChecker $emailAvailabilityChecker |
| 18 | ) { |
| 19 | } |
| 20 | |
| 21 | public function createIdentity(string $email, string $username, string $password): ?Identity |
| 22 | { |
| 23 | if (!$this->identityAvailabilityChecker->isIdentityAvailable($email, $username)) { |
| 24 | throw new EntityAlreadyExistsException('Identity already exists'); |
| 25 | } |
| 26 | return Identity::create(EntityId::generate(), $email, $username, $this->passwordHasher->hash($password)); |
| 27 | } |
| 28 | |
| 29 | public function changeEmail(Identity $identity, string $email): Identity |
| 30 | { |
| 31 | if ($identity->getEmail() === $email) { |
| 32 | return $identity; |
| 33 | } |
| 34 | |
| 35 | if (!$this->emailAvailabilityChecker->isEmailAvailable($email)) { |
| 36 | throw new EntityAlreadyExistsException('Email is taken'); |
| 37 | } |
| 38 | |
| 39 | return $identity->changeEmail($email); |
| 40 | } |
| 41 | |
| 42 | public function complete(Identity $identity): Identity |
| 43 | { |
| 44 | if ($identity->isComplete()) { |
| 45 | return $identity; |
| 46 | } |
| 47 | |
| 48 | return $identity->complete(); |
| 49 | } |