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\FamilyLog\Handler; |
15
|
|
|
|
16
|
|
|
use Administration\Domain\FamilyLog\Command\EditFamilyLog; |
17
|
|
|
use Administration\Domain\FamilyLog\Model\FamilyLog; |
18
|
|
|
use Administration\Domain\Protocol\Repository\FamilyLogRepositoryProtocol; |
19
|
|
|
use Core\Domain\Protocol\Common\Command\CommandHandlerProtocol; |
20
|
|
|
|
21
|
|
|
class EditFamilyLogHandler implements CommandHandlerProtocol |
22
|
|
|
{ |
23
|
|
|
private FamilyLogRepositoryProtocol $repository; |
24
|
|
|
|
25
|
|
|
public function __construct(FamilyLogRepositoryProtocol $repository) |
26
|
|
|
{ |
27
|
|
|
$this->repository = $repository; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function __invoke(EditFamilyLog $command): void |
31
|
|
|
{ |
32
|
|
|
if ($this->repository->existWithLabel($command->label()->getValue(), $command->parent())) { |
33
|
|
|
throw new \DomainException("FamilyLog with name: {$command->label()->getValue()} already exist!"); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$familyLogToUpdate = $this->repository->findParent($command->uuid()->toString()); |
37
|
|
|
|
38
|
|
|
$familyLog = $this->updateFamilyLog($familyLogToUpdate, $command); |
39
|
|
|
|
40
|
|
|
$this->repository->update($familyLog); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
private function updateFamilyLog(FamilyLog $familyLog, EditFamilyLog $command): FamilyLog |
44
|
|
|
{ |
45
|
|
|
$parent = null; |
46
|
|
|
if ($familyLog->label() !== $command->label()->getValue()) { |
47
|
|
|
$familyLog->rename($command->label()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if (null !== $command->parent()) { |
51
|
|
|
$parent = $this->repository->findParent($command->parent()); |
52
|
|
|
if ((null !== $familyLog->parent()) && ($familyLog->parent()->uuid() !== $parent->uuid())) { |
53
|
|
|
$familyLog->attributeParent($parent); |
54
|
|
|
} else { |
55
|
|
|
$familyLog->attributeParent($parent); |
56
|
|
|
} |
57
|
|
|
} elseif (null === $command->parent() && null !== $familyLog->parent()) { |
|
|
|
|
58
|
|
|
$familyLog->attributeParent($parent); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $familyLog; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.