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

UpdateCompany   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 11 2
A __construct() 0 4 1
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