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

CreateIdentityHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 10 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
    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