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

JobsService::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\Entities\Job;
7
use App\Domain\ValueObjects\JobDescription;
8
use App\Infrastructure\MultiDispatcher;
9
use App\Infrastructure\StrictObjectManager;
10
use Ramsey\Uuid\Uuid;
11
use Ramsey\Uuid\UuidInterface;
12
13
final class JobsService
14
{
15
    /** @var StrictObjectManager */
16
    private $entityManager;
17
18
    /** @var MultiDispatcher */
19
    private $dispatcher;
20
21
    public function __construct(StrictObjectManager $entityManager, MultiDispatcher $dispatcher)
22
    {
23
        $this->entityManager = $entityManager;
24
        $this->dispatcher = $dispatcher;
25
    }
26
27
    /**
28
     * Return job's id.
29
     *
30
     * @param UuidInterface $clientId
31
     * @param \App\Domain\ValueObjects\JobDescription $description
32
     * @return UuidInterface
33
     */
34
    public function post(UuidInterface $clientId, JobDescription $description): UuidInterface
35
    {
36
        /** @var Client $client */
37
        $client = $this->entityManager->findOrFail(Client::class, $clientId);
38
39
        $job = Job::post(Uuid::uuid4(), $client, $description);
40
41
        $this->entityManager->persist($job);
42
        $this->entityManager->flush();
43
44
        $this->dispatcher->multiDispatch($job->releaseEvents());
45
46
        return $job->getId();
47
    }
48
}