Passed
Push — master ( 81bbde...2ac216 )
by Adel
05:46
created

ClientsService::getById()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Services;
4
5
use App\Domain\Entities\Client;
6
use App\Domain\ValueObjects\Email;
7
use App\Infrastructure\MultiDispatcher;
8
use App\Infrastructure\StrictObjectManager;
9
use Ramsey\Uuid\Uuid;
10
use Ramsey\Uuid\UuidInterface;
11
12
final class ClientsService
13
{
14
    /** @var StrictObjectManager */
15
    private $entityManager;
16
17
    /** @var MultiDispatcher */
18
    private $dispatcher;
19
20
    public function __construct(StrictObjectManager $entityManager, MultiDispatcher $dispatcher)
21
    {
22
        $this->entityManager = $entityManager;
23
        $this->dispatcher = $dispatcher;
24
    }
25
26
    /**
27
     * Return client's id.
28
     *
29
     * @param \App\Domain\ValueObjects\Email $email
30
     * @return UuidInterface
31
     */
32
    public function register(Email $email): UuidInterface
33
    {
34
        $client = Client::register(Uuid::uuid4(), $email);
35
36
        $this->entityManager->persist($client);
37
        $this->entityManager->flush();
38
39
        $this->dispatcher->multiDispatch($client->releaseEvents());
40
41
        return $client->getId();
42
    }
43
}