| Conditions | 1 |
| Paths | 1 |
| Total Lines | 64 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 20 | public function testHappyPath() { |
||
| 21 | $fileFetcher = new InMemoryFileFetcher( [ |
||
| 22 | self::NEW_YORK_FETCH_URL |
||
| 23 | => '{ |
||
| 24 | "results" : [ |
||
| 25 | { |
||
| 26 | "address_components" : [ |
||
| 27 | { |
||
| 28 | "long_name" : "New York", |
||
| 29 | "short_name" : "New York", |
||
| 30 | "types" : [ "locality", "political" ] |
||
| 31 | }, |
||
| 32 | { |
||
| 33 | "long_name" : "New York", |
||
| 34 | "short_name" : "NY", |
||
| 35 | "types" : [ "administrative_area_level_1", "political" ] |
||
| 36 | }, |
||
| 37 | { |
||
| 38 | "long_name" : "United States", |
||
| 39 | "short_name" : "US", |
||
| 40 | "types" : [ "country", "political" ] |
||
| 41 | } |
||
| 42 | ], |
||
| 43 | "formatted_address" : "New York, NY, USA", |
||
| 44 | "geometry" : { |
||
| 45 | "bounds" : { |
||
| 46 | "northeast" : { |
||
| 47 | "lat" : 40.9175771, |
||
| 48 | "lng" : -73.70027209999999 |
||
| 49 | }, |
||
| 50 | "southwest" : { |
||
| 51 | "lat" : 40.4773991, |
||
| 52 | "lng" : -74.25908989999999 |
||
| 53 | } |
||
| 54 | }, |
||
| 55 | "location" : { |
||
| 56 | "lat" : 40.7127837, |
||
| 57 | "lng" : -74.0059413 |
||
| 58 | }, |
||
| 59 | "location_type" : "APPROXIMATE", |
||
| 60 | "viewport" : { |
||
| 61 | "northeast" : { |
||
| 62 | "lat" : 40.9175771, |
||
| 63 | "lng" : -73.70027209999999 |
||
| 64 | }, |
||
| 65 | "southwest" : { |
||
| 66 | "lat" : 40.4773991, |
||
| 67 | "lng" : -74.25908989999999 |
||
| 68 | } |
||
| 69 | } |
||
| 70 | }, |
||
| 71 | "place_id" : "ChIJOwg_06VPwokRYv534QaPC8g", |
||
| 72 | "types" : [ "locality", "political" ] |
||
| 73 | } |
||
| 74 | ], |
||
| 75 | "status" : "OK" |
||
| 76 | }' |
||
| 77 | ] ); |
||
| 78 | |||
| 79 | $geocoder = $this->newGeocoder( $fileFetcher ); |
||
| 80 | |||
| 81 | $this->assertSame( 40.7127837, $geocoder->geocode( 'New York' )->getLatitude() ); |
||
| 82 | $this->assertSame( -74.0059413, $geocoder->geocode( 'New York' )->getLongitude() ); |
||
| 83 | } |
||
| 84 | |||
| 115 |