UnitListUseCase   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 56
wmc 6
lcom 1
cbo 4
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 6 1
A fetchList() 0 14 2
A unitListFetched() 0 7 2
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));
0 ignored issues
show
Bug introduced by
The method unitListFetched() does not seem to exist on object<Domain\Common\UseCase\ResponderInterface>.

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.

Loading history...
73
        }
74
    }
75
}
76