Passed
Push — develop ( e3219b...3a1d34 )
by Laurent
01:38
created

ReadCompany   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A findOneByUuid() 0 9 2
A findAll() 0 3 1
A companyExist() 0 3 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\Company;
15
16
use Company\Domain\Exception\CompanyNotFoundException;
17
use Company\Domain\Model\Company as CompanyModel;
18
use Company\Domain\Storage\Company\ReadCompany as ReadCompanyDomain;
19
use Company\Infrastructure\Doctrine\Entity\Company;
20
use Company\Infrastructure\Doctrine\Repository\CompanyRepository;
21
use Core\Domain\Common\Model\VO\ResourceUuid;
22
23
class ReadCompany implements ReadCompanyDomain
24
{
25
    private CompanyRepository $companyRepository;
26
27
    public function __construct(CompanyRepository $companyRepository)
28
    {
29
        $this->companyRepository = $companyRepository;
30
    }
31
32
    public function findOneByUuid(string $uuid): CompanyModel
33
    {
34
        $company = $this->companyRepository->findOneByUuid(ResourceUuid::fromString($uuid));
35
36
        if (!$company instanceof Company) {
37
            throw new CompanyNotFoundException();
38
        }
39
40
        return $company->toModel();
41
    }
42
43
    public function companyExist(): bool
44
    {
45
        return $this->companyRepository->companyExist();
46
    }
47
48
    public function findAll(): array
49
    {
50
        return $this->companyRepository->findAll();
51
    }
52
}
53