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

CreateCompany::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
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\Application\Handler;
15
16
use Company\Application\Command\CreateCompany as CreateCompanyCommand;
17
use Company\Application\Factory\CreateCompany as CreateCompanyFactory;
18
use Company\Domain\Exception\CompanyAlreadyExistException;
19
use Company\Infrastructure\Storage\ReadCompany;
20
use Company\Infrastructure\Storage\SaveCompany;
21
use Core\Domain\Protocol\Common\Command\CommandHandlerInterface;
22
23
final class CreateCompany implements CommandHandlerInterface
24
{
25
    private ReadCompany $readCompany;
26
    private SaveCompany $saveCompany;
27
    private CreateCompanyFactory $createCompany;
28
29
    public function __construct(
30
        ReadCompany $readCompany,
31
        SaveCompany $saveCompany,
32
        CreateCompanyFactory $createCompany
33
    ) {
34
        $this->readCompany = $readCompany;
35
        $this->saveCompany = $saveCompany;
36
        $this->createCompany = $createCompany;
37
    }
38
39
    public function __invoke(CreateCompanyCommand $command): void
40
    {
41
        if ($this->readCompany->companyExist()) {
42
            throw new CompanyAlreadyExistException();
43
        }
44
45
        $company = $this->createCompany->createCompany($command);
46
47
        $this->saveCompany->save($company);
48
    }
49
}
50