1 | <?php |
||
5 | abstract class Mapper |
||
6 | { |
||
7 | /** |
||
8 | * @param Collection $collection |
||
9 | * @param array $data |
||
10 | * @param string $entityClass |
||
11 | * @param string $mapperClass |
||
12 | * @return Collection|mixed |
||
13 | */ |
||
14 | 4 | protected function create(Collection $collection, array $data, string $entityClass, string $mapperClass) |
|
22 | |||
23 | /** |
||
24 | * @param Collection $collection |
||
25 | * @param array $data |
||
26 | * @param string $entityClass |
||
27 | * @param string $mapperClass |
||
28 | * @return Collection|mixed |
||
29 | */ |
||
30 | 11 | protected function replace(Collection $collection, array $data, string $entityClass, string $mapperClass) |
|
41 | |||
42 | 11 | private function getCollectionItems(Collection $items): array |
|
54 | |||
55 | 11 | private function createOrReplaceEntity( |
|
56 | array $data, array $items, Collection $collection, string $entityClass, string $mapperClass |
||
57 | ): array { |
||
58 | 11 | if (isset($data['id'])) { |
|
59 | 11 | if (isset($items[$data['id']])) { |
|
60 | /** |
||
61 | * @var string $key |
||
62 | * @var Entity $item |
||
63 | */ |
||
64 | 1 | [$key, $item] = $items[$data['id']]; |
|
65 | 1 | unset($items[$data['id']]); |
|
66 | 1 | $collection[$key] = (new $mapperClass())->map($item, $data); |
|
67 | 1 | return $items; |
|
68 | } |
||
69 | } |
||
70 | 11 | $this->createEntity($data, $collection, $entityClass, $mapperClass); |
|
71 | 11 | return $items; |
|
72 | } |
||
73 | |||
74 | 11 | private function createEntity( |
|
82 | } |
||
83 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.