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\CreateUnit; |
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
|
|
|
use Domain\Unit\UnitFactoryInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class CreateUnitUseCase |
18
|
|
|
* |
19
|
|
|
* @package Domain\Unit\UseCase\CreateUnit |
20
|
|
|
*/ |
21
|
|
|
class CreateUnitUseCase implements ResponderAwareInterface |
22
|
|
|
{ |
23
|
|
|
use ResponderAwareTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var UnitRepositoryInterface |
27
|
|
|
*/ |
28
|
|
|
private $unitRepository; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var UnitFactoryInterface |
32
|
|
|
*/ |
33
|
|
|
private $unitFactory; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* CreateUnitUseCase constructor. |
37
|
|
|
* |
38
|
|
|
* @param UnitRepositoryInterface $unitRepository |
39
|
|
|
* @param UnitFactoryInterface $unitFactory |
40
|
|
|
*/ |
41
|
|
|
public function __construct(UnitRepositoryInterface $unitRepository, UnitFactoryInterface $unitFactory) |
42
|
|
|
{ |
43
|
|
|
$this->unitRepository = $unitRepository; |
44
|
|
|
$this->unitFactory = $unitFactory; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param CreateUnitRequest $request |
49
|
|
|
*/ |
50
|
|
|
public function execute(CreateUnitRequest $request) |
51
|
|
|
{ |
52
|
|
|
$unit = $this->unitFactory->create($request->getName(), $request->getShortcut()); |
53
|
|
|
$this->unitRepository->add($unit); |
54
|
|
|
$this->unitCreated($unit); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param UnitInterface $unit |
59
|
|
|
*/ |
60
|
|
|
private function unitCreated(UnitInterface $unit) |
61
|
|
|
{ |
62
|
|
|
/** @var CreateUnitResponderInterface $responder */ |
63
|
|
|
foreach ($this->responders as $responder) { |
64
|
|
|
$responder->unitCreated(new CreateUnitResponse($unit->getName())); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
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.