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\ListUnit; |
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 UnitListUseCase |
17
|
|
|
* |
18
|
|
|
* @package Domain\Unit\UseCase\ListUnit |
19
|
|
|
*/ |
20
|
|
|
class UnitListUseCase implements ResponderAwareInterface |
21
|
|
|
{ |
22
|
|
|
use ResponderAwareTrait; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var UnitRepositoryInterface |
26
|
|
|
*/ |
27
|
|
|
private $unitRepository; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* UnitListUseCase constructor. |
31
|
|
|
* |
32
|
|
|
* @param UnitRepositoryInterface $unitRepository |
33
|
|
|
*/ |
34
|
|
|
public function __construct(UnitRepositoryInterface $unitRepository) |
35
|
|
|
{ |
36
|
|
|
$this->unitRepository = $unitRepository; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function execute() |
40
|
|
|
{ |
41
|
|
|
$units = $this->unitRepository->findAll(); |
42
|
|
|
$items = $this->fetchList($units); |
43
|
|
|
$this->unitListFetched($items); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param array $units |
48
|
|
|
* @return array |
49
|
|
|
*/ |
50
|
|
|
private function fetchList(array $units) |
51
|
|
|
{ |
52
|
|
|
$list = []; |
53
|
|
|
/** @var UnitInterface $unit */ |
54
|
|
|
foreach ($units as $unit) { |
55
|
|
|
$list[] = new UnitListItem( |
56
|
|
|
$unit->getId(), |
57
|
|
|
$unit->getName(), |
58
|
|
|
$unit->getShortcut() |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $list; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param array $items |
67
|
|
|
*/ |
68
|
|
|
private function unitListFetched(array $items) |
69
|
|
|
{ |
70
|
|
|
/** @var UnitListResponderInterface $responder */ |
71
|
|
|
foreach ($this->responders as $responder) { |
72
|
|
|
$responder->unitListFetched(new UnitListResponse($items)); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
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.