Conditions | 2 |
Paths | 1 |
Total Lines | 55 |
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 |
||
46 | public function testTwoLevelFeed() |
||
47 | { |
||
48 | $unit1 = new Unit('customer'); |
||
49 | $unit1->setIsEntityCondition(function ($map, $odlmap) { |
||
50 | return ($odlmap['email'] != $map['email']) && !empty($map['email']); |
||
51 | }); |
||
52 | $unit2 = new Unit('address'); |
||
53 | $unit2->setParent($unit1); |
||
54 | |||
55 | $unit3 = new Unit('address_data'); |
||
56 | $unit3->addSibling($unit2); |
||
57 | |||
58 | $bag = new SimpleBag(); |
||
59 | $bag->addSet([$unit1, $unit2, $unit3]); |
||
60 | |||
61 | $shaper = $this->getShaper($bag); |
||
62 | |||
63 | $rows = [ |
||
64 | ['email' => '[email protected]', 'name' => 'bob', 'street' => 'charity str.'], |
||
65 | ['email' => '[email protected]', 'name' => 'paul', 'street' => 'buckingham ave.'], |
||
66 | ['email' => null, 'name' => null, 'street' => 'mirabelle str.'], |
||
67 | ]; |
||
68 | $this->assertFalse($shaper->feed($rows[0])); |
||
69 | $this->assertSame([ |
||
70 | 'email' => '[email protected]', |
||
71 | 'name' => 'bob', |
||
72 | 'street' => 'charity str.', |
||
73 | 'address' => [ |
||
74 | [ |
||
75 | 'email' => '[email protected]', |
||
76 | 'name' => 'bob', |
||
77 | 'street' => 'charity str.', |
||
78 | ], |
||
79 | ] |
||
80 | ], $shaper->feed($rows[1])); |
||
81 | $this->assertFalse($shaper->feed($rows[2])); |
||
82 | $this->assertSame([ |
||
83 | 'email' => '[email protected]', |
||
84 | 'name' => 'paul', |
||
85 | 'street' => 'buckingham ave.', |
||
86 | 'address' => [ |
||
87 | [ |
||
88 | 'email' => '[email protected]', |
||
89 | 'name' => 'paul', |
||
90 | 'street' => 'buckingham ave.', |
||
91 | ], |
||
92 | [ |
||
93 | 'email' => null, |
||
94 | 'name' => null, |
||
95 | 'street' => 'mirabelle str.', |
||
96 | ], |
||
97 | ] |
||
98 | ], $shaper->feed([])); |
||
99 | $this->assertFalse($shaper->feed([])); |
||
100 | } |
||
101 | |||
198 |