Conditions | 1 |
Paths | 1 |
Total Lines | 107 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
186 | public function testProcess2() |
||
187 | { |
||
188 | $inputs = [ |
||
189 | [ |
||
190 | 'email' => '[email protected]', |
||
191 | 'name' => 'Olaf Stone', |
||
192 | 'age' => 30, |
||
193 | 'addr_city' => 'Chicago', |
||
194 | 'addr_street' => '4100 Marine dr. App. 54', |
||
195 | 'address' => [ |
||
196 | [ |
||
197 | 'email' => '[email protected]', |
||
198 | 'name' => 'Olaf Stone', |
||
199 | 'age' => 30, |
||
200 | 'addr_city' => 'Chicago', |
||
201 | 'addr_street' => '4100 Marine dr. App. 54', |
||
202 | ], |
||
203 | [ |
||
204 | 'email' => '[email protected]', |
||
205 | 'name' => 'Olaf Stone', |
||
206 | 'age' => 30, |
||
207 | 'addr_city' => 'New York', |
||
208 | 'addr_street' => '3300 St. George, Suite 300', |
||
209 | ], |
||
210 | ] |
||
211 | ], |
||
212 | [ |
||
213 | 'email' => '[email protected]', |
||
214 | 'name' => 'Peter Ostridge', |
||
215 | 'age' => 33, |
||
216 | 'addr_city' => 'Chicago', |
||
217 | 'addr_street' => '111 W Jackson', |
||
218 | 'address' => [ |
||
219 | [ |
||
220 | 'email' => '[email protected]', |
||
221 | 'name' => 'Peter Ostridge', |
||
222 | 'age' => 33, |
||
223 | 'addr_city' => 'Chicago', |
||
224 | 'addr_street' => '111 W Jackson', |
||
225 | ] |
||
226 | ] |
||
227 | ], |
||
228 | false |
||
229 | ]; |
||
230 | $unit1 = $this->getUnit('customer'); |
||
231 | $unit1->setMapping([ |
||
232 | 'id' => 'map.id', |
||
233 | 'fname' => function ($map) { |
||
234 | list($fname) = explode(" ", $map['name']); |
||
235 | return $fname; |
||
236 | }, |
||
237 | 'lname' => function ($map) { |
||
238 | list(, $lname) = explode(" ", $map['name']); |
||
239 | return $lname; |
||
240 | }, |
||
241 | 'email' => 'map.email', |
||
242 | 'age' => 'map.age', |
||
243 | ]); |
||
244 | $unit1->addContribution(function (MapInterface $map) { |
||
245 | $map->frozenIncr('id', 1); |
||
246 | }); |
||
247 | $unit1->setFilesystem($this->getFS( |
||
248 | [ |
||
249 | [[1, 'Olaf', 'Stone', '[email protected]', 30]], |
||
250 | [[2, 'Peter', 'Ostridge', '[email protected]', 33]], |
||
251 | ] |
||
252 | )); |
||
253 | $unit1->setIsEntityCondition(function ( |
||
254 | MapInterface $map, |
||
255 | MapInterface $oldmap |
||
256 | ) { |
||
257 | return $oldmap->offsetGet('email') != $map->offsetGet('email'); |
||
258 | }); |
||
259 | $unit2 = $this->getUnit('address'); |
||
260 | $unit2->setMapping([ |
||
261 | 'id' => 'map.addr_id', |
||
262 | 'street' => 'map.addr_street', |
||
263 | 'city' => 'map.addr_city', |
||
264 | 'parent_id' => 'map.id', |
||
265 | ]); |
||
266 | $unit2->addContribution(function (MapInterface $map) { |
||
267 | $map->incr('addr_id', 1); |
||
268 | }); |
||
269 | $unit2->setFilesystem($this->getFS( |
||
270 | [ |
||
271 | [[1, '4100 Marine dr. App. 54', 'Chicago', 1]], |
||
272 | [[2, '3300 St. George, Suite 300', 'New York', 1]], |
||
273 | [[3, '111 W Jackson', 'Chicago', 2]], |
||
274 | ] |
||
275 | )); |
||
276 | $unit2->setParent($unit1); |
||
277 | |||
278 | $action = new CreateTmpFiles( |
||
279 | $this->getUnitBag([$unit1, $unit2]), |
||
280 | $this->getConfig(), |
||
281 | new LanguageAdapter(new ExpressionLanguage()), |
||
282 | $this->getInputResource($inputs), |
||
283 | new ArrayMap(), |
||
284 | $this->getResourceHelper() |
||
285 | ); |
||
286 | $action->process($this->getResultMock()); |
||
287 | |||
288 | $this->assertEquals('/tmp/customer.csv', |
||
289 | $unit1->getTmpFileName()); |
||
290 | $this->assertEquals('/tmp/address.csv', |
||
291 | $unit2->getTmpFileName()); |
||
292 | } |
||
293 | |||
343 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.