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) |
|
31 | { |
||
32 | 11 | $items = $this->getCollectionItems($collection); |
|
33 | 11 | foreach ($data as $element) { |
|
34 | 11 | $items = $this->createOrReplaceEntity($element, $items, $collection, $entityClass, $mapperClass); |
|
35 | } |
||
36 | 11 | foreach ($items as $id => [$key, $item]) { |
|
37 | unset($collection[$key]); |
||
38 | } |
||
39 | 11 | return $collection; |
|
40 | } |
||
41 | |||
42 | 11 | private function getCollectionItems(Collection $items): array |
|
43 | { |
||
44 | 11 | $finalItems = []; |
|
45 | /** |
||
46 | * @var string $key |
||
47 | * @var ReplaceableEntity $item |
||
48 | */ |
||
49 | 11 | foreach ($items as $key => $item) { |
|
50 | $finalItems[$item->getId()] = [$key, $item]; |
||
51 | } |
||
52 | 11 | return $finalItems; |
|
53 | } |
||
54 | |||
55 | 11 | private function createOrReplaceEntity( |
|
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.