| Conditions | 2 |
| Paths | 1 |
| Total Lines | 95 |
| 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 |
||
| 102 | public function testThreeLevelFeed() |
||
| 103 | { |
||
| 104 | $unit1 = new Unit('customer'); |
||
| 105 | $unit1->setIsEntityCondition(function ($map, $odlmap) { |
||
| 106 | return ($odlmap['email'] != $map['email']) && !empty($map['email']); |
||
| 107 | }); |
||
| 108 | $unit2 = new Unit('address'); |
||
| 109 | $unit2->setParent($unit1); |
||
| 110 | $unit2->setIsEntityCondition(function ($map, $oldmap) { |
||
| 111 | return $map['street'] != $oldmap['street']; |
||
| 112 | }); |
||
| 113 | |||
| 114 | $unit3 = new Unit('address_data'); |
||
| 115 | $unit3->setParent($unit2); |
||
| 116 | |||
| 117 | $bag = new SimpleBag(); |
||
| 118 | $bag->addSet([$unit1, $unit2, $unit3]); |
||
| 119 | |||
| 120 | $shaper = $this->getShaper($bag); |
||
| 121 | |||
| 122 | $rows = [ |
||
| 123 | ['email' => '[email protected]', 'name' => 'bob', 'street' => 'charity str.', 'phone' => '123'], |
||
| 124 | ['email' => null, 'name' => null, 'street' => 'charity str.', 'phone' => '432'], |
||
| 125 | ['email' => '[email protected]', 'name' => 'paul', 'street' => 'buckingham ave.', 'phone' => '222'], |
||
| 126 | ['email' => null, 'name' => null, 'street' => 'mirabelle str.', 'phone' => '323'], |
||
| 127 | ]; |
||
| 128 | $this->assertFalse($shaper->feed($rows[0])); |
||
| 129 | $this->assertFalse($shaper->feed($rows[1])); |
||
| 130 | $this->assertSame([ |
||
| 131 | 'email' => '[email protected]', |
||
| 132 | 'name' => 'bob', |
||
| 133 | 'street' => 'charity str.', |
||
| 134 | 'phone' => '123', |
||
| 135 | 'address' => [ |
||
| 136 | [ |
||
| 137 | 'email' => '[email protected]', |
||
| 138 | 'name' => 'bob', |
||
| 139 | 'street' => 'charity str.', |
||
| 140 | 'phone' => '123', |
||
| 141 | 'address_data' => [ |
||
| 142 | [ |
||
| 143 | 'email' => '[email protected]', |
||
| 144 | 'name' => 'bob', |
||
| 145 | 'street' => 'charity str.', |
||
| 146 | 'phone' => '123', |
||
| 147 | ], |
||
| 148 | [ |
||
| 149 | 'email' => null, |
||
| 150 | 'name' => null, |
||
| 151 | 'street' => 'charity str.', |
||
| 152 | 'phone' => '432', |
||
| 153 | ] |
||
| 154 | ], |
||
| 155 | ], |
||
| 156 | ] |
||
| 157 | ], $shaper->feed($rows[2])); |
||
| 158 | $this->assertFalse($shaper->feed($rows[3])); |
||
| 159 | $this->assertSame([ |
||
| 160 | 'email' => '[email protected]', |
||
| 161 | 'name' => 'paul', |
||
| 162 | 'street' => 'buckingham ave.', |
||
| 163 | 'phone' => '222', |
||
| 164 | 'address' => [ |
||
| 165 | [ |
||
| 166 | 'email' => '[email protected]', |
||
| 167 | 'name' => 'paul', |
||
| 168 | 'street' => 'buckingham ave.', |
||
| 169 | 'phone' => '222', |
||
| 170 | 'address_data' => [ |
||
| 171 | [ |
||
| 172 | 'email' => '[email protected]', |
||
| 173 | 'name' => 'paul', |
||
| 174 | 'street' => 'buckingham ave.', |
||
| 175 | 'phone' => '222', |
||
| 176 | ] |
||
| 177 | ], |
||
| 178 | ], |
||
| 179 | [ |
||
| 180 | 'email' => null, |
||
| 181 | 'name' => null, |
||
| 182 | 'street' => 'mirabelle str.', |
||
| 183 | 'phone' => '323', |
||
| 184 | 'address_data' => [ |
||
| 185 | [ |
||
| 186 | 'email' => null, |
||
| 187 | 'name' => null, |
||
| 188 | 'street' => 'mirabelle str.', |
||
| 189 | 'phone' => '323', |
||
| 190 | ] |
||
| 191 | ], |
||
| 192 | ], |
||
| 193 | ] |
||
| 194 | ], $shaper->feed([])); |
||
| 195 | $this->assertFalse($shaper->feed([])); |
||
| 196 | } |
||
| 197 | } |
||
| 198 |