Passed
Push — develop ( 7d2e81...61e6f0 )
by Laurent
06:22 queued 03:53
created

CompanyFactory::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 1
dl 0
loc 14
rs 9.8666
c 0
b 0
f 0
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 Administration\Domain\Company;
15
16
use Administration\Domain\Company\Command\CreateCompany;
17
use Administration\Domain\Company\Command\EditCompany;
18
use Administration\Domain\Company\Model\Company;
19
use Core\Domain\Common\Model\VO\ContactUuid;
20
21
final class CompanyFactory
22
{
23
    public function create(CreateCompany $command): Company
24
    {
25
        return Company::create(
26
            ContactUuid::generate(),
27
            $command->name(),
28
            $command->address(),
29
            $command->zipCode(),
30
            $command->town(),
31
            $command->country(),
32
            $command->phone(),
33
            $command->facsimile(),
34
            $command->email(),
35
            $command->contact(),
36
            $command->cellPhone()
37
        );
38
    }
39
40
    public function update(EditCompany $command, Company $company): Company
41
    {
42
        if ($company->name() !== $command->name()) {
0 ignored issues
show
introduced by
The condition $company->name() !== $command->name() is always true.
Loading history...
43
            $company->renameCompany($command->name());
44
        }
45
        if (($company->address() !== $command->address())
46
            || ($company->zipCode() !== $command->zipCode())
47
            || ($company->town() !== $command->town())
48
            || ($company->country() !== $command->country())
49
        ) {
50
            $company->rewriteAddress([
51
                $command->address(),
52
                $command->zipCode(),
53
                $command->town(),
54
                $command->country(),
55
            ]);
56
        }
57
        if ($company->phone() !== $command->phone()) {
0 ignored issues
show
introduced by
The condition $company->phone() !== $command->phone() is always true.
Loading history...
58
            $company->changePhoneNumber($command->phone());
59
        }
60
        if ($company->facsimile() !== $command->facsimile()) {
0 ignored issues
show
introduced by
The condition $company->facsimile() !== $command->facsimile() is always true.
Loading history...
61
            $company->changeFacsimileNumber($command->facsimile());
62
        }
63
        if ($company->email() !== $command->email()) {
0 ignored issues
show
introduced by
The condition $company->email() !== $command->email() is always true.
Loading history...
64
            $company->rewriteEmail($command->email());
65
        }
66
        if ($company->contact() !== $command->contact()) {
67
            $company->renameContact($command->contact());
68
        }
69
        if ($company->cellPhone() !== $command->cellPhone()) {
0 ignored issues
show
introduced by
The condition $company->cellPhone() !== $command->cellPhone() is always true.
Loading history...
70
            $company->changeCellphoneNumber($command->cellPhone());
71
        }
72
73
        return $company;
74
    }
75
}
76