Passed
Push — develop ( 577144...bf5480 )
by
unknown
01:39
created

UpdateCompany::update()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 11
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the G.L.S.R. Apps package.
7
 *
8
 * (c) Dev-Int Création <[email protected]>.
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Company\Infrastructure\Storage;
15
16
use Company\Domain\Model\Company as CompanyModel;
17
use Company\Infrastructure\Doctrine\Repository\CompanyRepository;
18
19
class UpdateCompany
20
{
21
    private CompanyRepository $companyRepository;
22
    private ReadCompany $readCompany;
23
24
    public function __construct(CompanyRepository $companyRepository, ReadCompany $readCompany)
25
    {
26
        $this->companyRepository = $companyRepository;
27
        $this->readCompany = $readCompany;
28
    }
29
30
    public function update(CompanyModel $companyModel): void
31
    {
32
        $companyEntity = $this->readCompany->findOneByUuid($companyModel->uuid());
33
34
        if (null === $companyEntity) {
35
            throw new \DomainException('Company provided does not exist !');
36
        }
37
38
        $companyEntity->update($companyModel);
39
40
        $this->companyRepository->flush();
41
    }
42
}
43