1 | <?php |
||
60 | class MergeUsingDotNotationPath |
||
61 | { |
||
62 | /** |
||
63 | * merge their data into our array, using dot.notation.support to |
||
64 | * find the point where the merge starts |
||
65 | * |
||
66 | * @param array &$arr |
||
67 | * the array that we want to merge into |
||
68 | * @param string $path |
||
69 | * the dot.notation.support path to where the merge should start |
||
70 | * @param mixed $value |
||
71 | * the data that we want to merge from |
||
72 | * @param array|callable|string|null |
||
73 | * if $path goes beyond what exists in $ours, how do we want to |
||
74 | * extend $ours? |
||
75 | * @return void |
||
76 | */ |
||
77 | public static function intoArray(&$arr, $path, $value, $extendingItem = null) |
||
78 | { |
||
79 | // robustness! |
||
80 | RequireIndexable::check($arr, E4xx_UnsupportedType::class); |
||
81 | RequireDotNotationPath::check($path); |
||
82 | |||
83 | // find the point where we want to merge |
||
84 | list ($firstPart, $finalPart) = self::splitPathInTwo($path); |
||
85 | if ($firstPart !== null) { |
||
86 | $leaf =& DescendDotNotationPath::intoArray($arr, $firstPart, $extendingItem); |
||
87 | } |
||
88 | else { |
||
89 | $leaf =& $arr; |
||
90 | } |
||
91 | |||
92 | // merge it |
||
93 | MergeIntoProperty::of($leaf, $finalPart, $value); |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * merge their data into our object, using dot.notation.support to |
||
98 | * find the point where the merge starts |
||
99 | * |
||
100 | * @param object $obj |
||
101 | * the object that we want to merge into |
||
102 | * @param string $path |
||
103 | * the dot.notation.support path to where the merge should start |
||
104 | * @param mixed $value |
||
105 | * the data that we want to merge from |
||
106 | * @param array|callable|string|null |
||
107 | * if $path goes beyond what exists in $ours, how do we want to |
||
108 | * extend $ours? |
||
109 | * @return void |
||
110 | */ |
||
111 | public static function intoObject($obj, $path, $value, $extendingItem = null) |
||
112 | { |
||
113 | // robustness! |
||
114 | RequireAssignable::check($obj, E4xx_UnsupportedType::class); |
||
115 | RequireDotNotationPath::check($path); |
||
116 | |||
117 | // find the point where we want to merge |
||
118 | list ($firstPart, $finalPart) = self::splitPathInTwo($path); |
||
119 | if ($firstPart !== null) { |
||
120 | $leaf =& DescendDotNotationPath::intoObject($obj, $firstPart, $extendingItem); |
||
121 | } |
||
122 | else { |
||
123 | $leaf = $obj; |
||
124 | } |
||
125 | |||
126 | // merge it |
||
127 | MergeIntoProperty::of($leaf, $finalPart, $value); |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * merge their data into our data, using dot.notation.support to |
||
132 | * find the point where the merge starts |
||
133 | * |
||
134 | * @param object $ours |
||
135 | * the object that we want to merge into |
||
136 | * @param string $path |
||
137 | * the dot.notation.support path to where the merge should start |
||
138 | * @param mixed $value |
||
139 | * the data that we want to merge from |
||
140 | * @param array|callable|string|null |
||
141 | * if $path goes beyond what exists in $ours, how do we want to |
||
142 | * extend $ours? |
||
143 | * @return void |
||
144 | */ |
||
145 | public static function into(&$ours, $path, $value, $extendingItem = null) |
||
156 | |||
157 | /** |
||
158 | * merge their data into our data, using dot.notation.support to |
||
159 | * find the point where the merge starts |
||
160 | * |
||
161 | * @deprecated since 2.2.0 |
||
162 | * @codeCoverageIgnore |
||
163 | * |
||
164 | * @param mixed $ours |
||
165 | * the data that we want to merge into |
||
166 | * @param string $path |
||
167 | * the dot.notation.support path to where the merge should start |
||
168 | * @param mixed $value |
||
169 | * the data that we want to merge from |
||
170 | * @param array|callable|string|null |
||
171 | * if $path goes beyond what exists in $ours, how do we want to |
||
172 | * extend $ours? |
||
173 | * @return void |
||
174 | */ |
||
175 | public static function intoMixed(&$ours, $path, $value, $extendingItem = null) |
||
179 | |||
180 | /** |
||
181 | * merge their data into our data, using dot.notation.support to |
||
182 | * find the point where the merge starts |
||
183 | * |
||
184 | * @param mixed $ours |
||
185 | * the data that we want to merge into |
||
186 | * @param string $path |
||
187 | * the dot.notation.support path to where the merge should start |
||
188 | * @param mixed $value |
||
189 | * the data that we want to merge from |
||
190 | * @param array|callable|string|null |
||
191 | * if $path goes beyond what exists in $ours, how do we want to |
||
192 | * extend $ours? |
||
193 | * @return void |
||
194 | */ |
||
195 | public function __invoke(&$ours, $path, $value, $extendingItem = null) |
||
199 | |||
200 | /** |
||
201 | * split the dot.notation.support path up into two parts - where we are |
||
202 | * inserting, and the name of what we are inserting |
||
203 | * |
||
204 | * @param string $path |
||
205 | * the dot.notation.support path that needs splitting |
||
206 | * @return array |
||
207 | * the two parts of the path |
||
208 | */ |
||
209 | private static function splitPathInTwo($path) |
||
226 | } |
||
227 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.