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()) { |
|
|
|
|
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()) { |
|
|
|
|
58
|
|
|
$company->changePhoneNumber($command->phone()); |
59
|
|
|
} |
60
|
|
|
if ($company->facsimile() !== $command->facsimile()) { |
|
|
|
|
61
|
|
|
$company->changeFacsimileNumber($command->facsimile()); |
62
|
|
|
} |
63
|
|
|
if ($company->email() !== $command->email()) { |
|
|
|
|
64
|
|
|
$company->rewriteEmail($command->email()); |
65
|
|
|
} |
66
|
|
|
if ($company->contact() !== $command->contact()) { |
67
|
|
|
$company->renameContact($command->contact()); |
68
|
|
|
} |
69
|
|
|
if ($company->cellPhone() !== $command->cellPhone()) { |
|
|
|
|
70
|
|
|
$company->changeCellphoneNumber($command->cellPhone()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return $company; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|