CreateIdentityHandler::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 1
dl 0
loc 15
ccs 10
cts 10
cp 1
crap 2
rs 9.9666
c 0
b 0
f 0
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