| Conditions | 8 |
| Paths | 21 |
| Total Lines | 73 |
| Code Lines | 46 |
| 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 |
||
| 159 | private function assertWellFormattedResult(Collection $result) |
||
| 160 | { |
||
| 161 | $this->assertInstanceOf( |
||
| 162 | Collection::class, |
||
| 163 | $result, |
||
| 164 | 'The result must be an instance of a Geocoder\Collection' |
||
| 165 | ); |
||
| 166 | |||
| 167 | /** @var Location $location */ |
||
| 168 | foreach ($result as $location) { |
||
| 169 | $this->assertInstanceOf( |
||
| 170 | Location::class, |
||
| 171 | $location, |
||
| 172 | 'All items in Geocoder\Collection must implement Geocoder\Location' |
||
| 173 | ); |
||
| 174 | |||
| 175 | $this->assertInstanceOf( |
||
| 176 | AdminLevelCollection::class, |
||
| 177 | $location->getAdminLevels(), |
||
| 178 | 'Location::getAdminLevels MUST always return a AdminLevelCollection' |
||
| 179 | ); |
||
| 180 | $arrayData = $location->toArray(); |
||
| 181 | $this->assertTrue(is_array($arrayData), 'Location::toArray MUST return an array.'); |
||
| 182 | $this->assertNotEmpty($arrayData, 'Location::toArray cannot be empty.'); |
||
| 183 | |||
| 184 | // Verify coordinates |
||
| 185 | if (null !== $coords = $location->getCoordinates()) { |
||
| 186 | $this->assertInstanceOf( |
||
| 187 | Coordinates::class, |
||
| 188 | $coords, |
||
| 189 | 'Location::getCoordinates MUST always return a Coordinates or null' |
||
| 190 | ); |
||
| 191 | |||
| 192 | // Using "assertNotEmpty" means that we can not have test code where coordinates is on equator or long = 0 |
||
| 193 | $this->assertNotEmpty($coords->getLatitude(), 'If coordinate object exists it cannot have an empty latitude.'); |
||
| 194 | $this->assertNotEmpty($coords->getLongitude(), 'If coordinate object exists it cannot have an empty longitude.'); |
||
| 195 | } |
||
| 196 | |||
| 197 | // Verify bounds |
||
| 198 | if (null !== $bounds = $location->getBounds()) { |
||
| 199 | $this->assertInstanceOf( |
||
| 200 | Bounds::class, |
||
| 201 | $bounds, |
||
| 202 | 'Location::getBounds MUST always return a Bounds or null' |
||
| 203 | ); |
||
| 204 | |||
| 205 | // Using "assertNotEmpty" means that we can not have test code where coordinates is on equator or long = 0 |
||
| 206 | $this->assertNotEmpty($bounds->getSouth(), 'If bounds object exists it cannot have an empty values.'); |
||
| 207 | $this->assertNotEmpty($bounds->getWest(), 'If bounds object exists it cannot have an empty values.'); |
||
| 208 | $this->assertNotEmpty($bounds->getNorth(), 'If bounds object exists it cannot have an empty values.'); |
||
| 209 | $this->assertNotEmpty($bounds->getEast(), 'If bounds object exists it cannot have an empty values.'); |
||
| 210 | } |
||
| 211 | |||
| 212 | // Check country |
||
| 213 | if (null !== $country = $location->getCountry()) { |
||
| 214 | $this->assertInstanceOf( |
||
| 215 | Country::class, |
||
| 216 | $country, |
||
| 217 | 'Location::getCountry MUST always return a Country or null' |
||
| 218 | ); |
||
| 219 | $this->assertFalse(null === $country->getCode() && null === $country->getName(), 'Both code and name cannot be empty'); |
||
| 220 | |||
| 221 | if (null !== $country->getCode()) { |
||
| 222 | $this->assertNotEmpty( |
||
| 223 | $location->getCountry()->getCode(), |
||
| 224 | 'The Country should not have an empty code.' |
||
| 225 | ); |
||
| 226 | } |
||
| 227 | |||
| 228 | if (null !== $country->getName()) { |
||
| 229 | $this->assertNotEmpty( |
||
| 230 | $location->getCountry()->getName(), |
||
| 231 | 'The Country should not have an empty name.' |
||
| 232 | ); |
||
| 238 |