CreateIdentityHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 24
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 15 2
A __construct() 0 3 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace PersonalGalaxy\Identity\Handler;
5
6
use PersonalGalaxy\Identity\{
7
    Command\CreateIdentity,
8
    Repository\IdentityRepository,
9
    Entity\Identity,
10
    Specification\Identity\Email,
11
    Exception\IdentityAlreadyExist,
12
};
13
14
final class CreateIdentityHandler
15
{
16
    private $repository;
17
18 2
    public function __construct(IdentityRepository $repository)
19
    {
20 2
        $this->repository = $repository;
21 2
    }
22
23 2
    public function __invoke(CreateIdentity $wished): void
24
    {
25 2
        $identities = $this->repository->matching(
26 2
            new Email($wished->email())
27
        );
28
29 2
        if ($identities->size() > 0) {
30 1
            throw new IdentityAlreadyExist($wished->email());
31
        }
32
33 1
        $this->repository->add(
34 1
            Identity::create(
35 1
                $wished->identity(),
36 1
                $wished->email(),
37 1
                $wished->password()
38
            )
39
        );
40 1
    }
41
}
42