@@ -44,23 +44,28 @@ public static function propMapToSelectMap(array $map): array
4444 $ selectMap = [];
4545
4646 foreach ($ map as $ prop ) {
47- $ key = $ prop ->map [0 ];
48- /** @psalm-suppress EmptyArrayAccess */
49- $ _ref = &$ selectMap [$ key ];
50-
51- for ($ i = 1 ; $ i < $ prop ->depth ; $ i ++) {
52- $ key = $ prop ->map [$ i ];
53- /** @psalm-suppress MixedArrayAccess */
54- $ _ref = &$ _ref [$ key ];
55- }
56-
57- $ _ref = $ prop ->col ;
58- unset($ _ref ); // dereference
47+ self ::setNestedValue ($ selectMap , $ prop ->map , $ prop ->col );
5948 }
6049
6150 return $ selectMap ;
6251 }
6352
53+ /**
54+ * @param array<string, mixed> $array
55+ * @param string[] $path
56+ */
57+ private static function setNestedValue (array &$ array , array $ path , mixed $ value ): void
58+ {
59+ $ arr = &$ array ;
60+
61+ foreach ($ path as $ key ) {
62+ /** @phpstan-ignore offsetAccess.nonOffsetAccessible */
63+ $ arr = &$ arr [$ key ];
64+ }
65+
66+ $ arr = $ value ;
67+ }
68+
6469 /**
6570 * @param \Generator<int, array> $rows
6671 * @param Prop[] $fieldProps
@@ -111,34 +116,12 @@ public static function mapRows(\Generator $rows, array $fieldProps): array
111116 continue ;
112117 }
113118
114- $ key = $ prop ->map [0 ];
115- /** @psalm-suppress EmptyArrayAccess */
116- $ _ref = &$ entity [$ key ];
117-
118- for ($ i = 1 ; $ i < $ prop ->depth ; $ i ++) {
119- $ key = $ prop ->map [$ i ];
120- /** @psalm-suppress MixedArrayAccess */
121- $ _ref = &$ _ref [$ key ];
122- }
123-
124- $ _ref = $ value ;
125- unset($ _ref ); // dereference
119+ self ::setNestedValue ($ entity , $ prop ->map , $ value );
126120 }
127121
128122 foreach ($ nullParents as $ prop ) {
129- $ depth = $ prop ->depth - 1 ;
130- $ key = $ prop ->map [0 ];
131- /** @psalm-suppress EmptyArrayAccess */
132- $ _ref = &$ entity [$ key ];
133-
134- for ($ i = 1 ; $ i < $ depth ; $ i ++) {
135- $ key = $ prop ->map [$ i ];
136- /** @psalm-suppress MixedArrayAccess */
137- $ _ref = &$ _ref [$ key ];
138- }
139-
140- $ _ref = null ;
141- unset($ _ref ); // dereference
123+ $ path = array_slice ($ prop ->map , 0 , -1 );
124+ self ::setNestedValue ($ entity , $ path , null );
142125 }
143126
144127 $ entities [] = $ entity ;
0 commit comments