|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* (c) Tomasz Kunicki <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
*/ |
|
8
|
|
|
namespace Domain\Unit\UseCase\EditUnit; |
|
9
|
|
|
|
|
10
|
|
|
use Domain\Common\UseCase\ResponderAwareInterface; |
|
11
|
|
|
use Domain\Common\UseCase\ResponderAwareTrait; |
|
12
|
|
|
use Domain\Unit\Enitity\UnitInterface; |
|
13
|
|
|
use Domain\Unit\Repository\UnitRepositoryInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class EditUnitUseCase |
|
17
|
|
|
* |
|
18
|
|
|
* @package Domain\Unit\UseCase\EditUnit |
|
19
|
|
|
*/ |
|
20
|
|
|
class EditUnitUseCase implements ResponderAwareInterface |
|
21
|
|
|
{ |
|
22
|
|
|
use ResponderAwareTrait; |
|
23
|
|
|
/** |
|
24
|
|
|
* @var UnitRepositoryInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
private $unitRepository; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* EditUnitUseCase constructor. |
|
30
|
|
|
* |
|
31
|
|
|
* @param UnitRepositoryInterface $unitRepository |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct(UnitRepositoryInterface $unitRepository) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->unitRepository = $unitRepository; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param EditUnitRequest $request |
|
40
|
|
|
*/ |
|
41
|
|
|
public function execute(EditUnitRequest $request) |
|
42
|
|
|
{ |
|
43
|
|
|
$unit = $this->unitRepository->findById($request->getUnitId()); |
|
44
|
|
|
if (is_null($unit)) { |
|
45
|
|
|
$this->unitNotFound(); |
|
46
|
|
|
|
|
47
|
|
|
return; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$unit->compose($request->getName(), $request->getShortcut()); |
|
51
|
|
|
$this->unitRepository->update($unit); |
|
52
|
|
|
|
|
53
|
|
|
$this->unitUpdated($unit); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param UnitInterface $unit |
|
58
|
|
|
*/ |
|
59
|
|
|
private function unitUpdated(UnitInterface $unit) |
|
60
|
|
|
{ |
|
61
|
|
|
/** @var EditUnitResponderInterface $responder */ |
|
62
|
|
|
foreach ($this->responders as $responder) { |
|
63
|
|
|
$responder->unitUpdated(new EditUnitResponse($unit->getName())); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
private function unitNotFound() |
|
68
|
|
|
{ |
|
69
|
|
|
/** @var EditUnitResponderInterface $responder */ |
|
70
|
|
|
foreach ($this->responders as $responder) { |
|
71
|
|
|
$responder->unitNotFound(); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.