Completed
Push — develop ( ccfc23...3b27a1 )
by Baptiste
02:20
created

CreateIdentityHandler::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 10
ccs 7
cts 7
cp 1
crap 2
rs 9.4285
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
    Exception\IdentityAlreadyExist,
11
};
12
13
final class CreateIdentityHandler
14
{
15
    private $repository;
16
17 2
    public function __construct(IdentityRepository $repository)
18
    {
19 2
        $this->repository = $repository;
20 2
    }
21
22 2
    public function __invoke(CreateIdentity $wished): void
23
    {
24 2
        if ($this->repository->has($wished->email())) {
25 1
            throw new IdentityAlreadyExist($wished->email());
26
        }
27
28 1
        $this->repository->add(
29 1
            Identity::create(
30 1
                $wished->email(),
31 1
                $wished->password()
32
            )
33
        );
34 1
    }
35
}
36