Total Complexity | 7 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
15 | class OrderedContainer implements ContainerInterface |
||
16 | { |
||
17 | /** @var FilteredContainerInterface */ |
||
18 | private $container; |
||
19 | /** @var ItemInterface[] */ |
||
20 | private $items; |
||
21 | |||
22 | public function __construct(ContainerInterface $container) |
||
23 | { |
||
24 | $this->container = $container; |
||
|
|||
25 | } |
||
26 | |||
27 | /** |
||
28 | * @return ItemInterface[] |
||
29 | */ |
||
30 | public function getItems(): array |
||
31 | { |
||
32 | if (!$this->items) { |
||
33 | $items = $this->container->getItems(); |
||
34 | |||
35 | $sortable = []; |
||
36 | foreach ($items as $key => $item) { |
||
37 | if ($item instanceof SortableInterface) { |
||
38 | $sortable[$key] = $item; |
||
39 | unset($items[$key]); |
||
40 | } |
||
41 | } |
||
42 | |||
43 | uasort($sortable, [$this, 'ascending']); |
||
44 | $this->items = array_merge($sortable, $items); |
||
45 | } |
||
46 | |||
47 | return $this->items; |
||
48 | } |
||
49 | |||
50 | public function get(string $name): ItemInterface |
||
51 | { |
||
52 | return $this->items[$name]; |
||
53 | } |
||
54 | |||
55 | private function ascending(SortableInterface $first, SortableInterface $second) |
||
58 | } |
||
59 | } |
||
60 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.