Passed
Push — develop ( 229fa6...7d2e81 )
by Laurent
08:00 queued 04:20
created

CompanyFactory   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 35
c 1
b 0
f 0
dl 0
loc 53
rs 10
wmc 12

2 Methods

Rating   Name   Duplication   Size   Complexity  
B update() 0 34 11
A create() 0 14 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 Domain\Administration\Company;
15
16
use Domain\Administration\Company\Command\CreateCompany;
17
use Domain\Administration\Company\Command\EditCompany;
18
use Domain\Administration\Company\Model\Company;
19
use Domain\Common\Model\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