| Conditions | 10 |
| Paths | 97 |
| Total Lines | 44 |
| 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 |
||
| 60 | public function parse( $value ) { |
||
| 61 | $separator = '~'; |
||
| 62 | |||
| 63 | $metaData = explode( $separator, $value ); |
||
| 64 | |||
| 65 | $coordinatesOrAddress = array_shift( $metaData ); |
||
| 66 | $coordinates = $this->geocoder->geocode( $coordinatesOrAddress ); |
||
| 67 | |||
| 68 | if ( $coordinates === null ) { |
||
| 69 | throw new ParseException( 'Location is not a parsable coordinate and not a geocodable address' ); |
||
| 70 | } |
||
| 71 | |||
| 72 | $location = new Location( $coordinates ); |
||
| 73 | |||
| 74 | if ( $metaData !== [] ) { |
||
| 75 | $this->setTitleOrLink( $location, array_shift( $metaData ) ); |
||
| 76 | } else { |
||
| 77 | if ( $this->useAddressAsTitle && $this->isAddress( $coordinatesOrAddress ) ) { |
||
| 78 | $location->setTitle( $coordinatesOrAddress ); |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | if ( $metaData !== [] ) { |
||
| 83 | $location->setText( array_shift( $metaData ) ); |
||
| 84 | } |
||
| 85 | |||
| 86 | if ( $metaData !== [] ) { |
||
| 87 | $location->setIcon( $this->fileUrlFinder->getUrlForFileName( array_shift( $metaData ) ) ); |
||
| 88 | } |
||
| 89 | |||
| 90 | if ( $metaData !== [] ) { |
||
| 91 | $location->setGroup( array_shift( $metaData ) ); |
||
| 92 | } |
||
| 93 | |||
| 94 | if ( $metaData !== [] ) { |
||
| 95 | $location->setInlineLabel( array_shift( $metaData ) ); |
||
| 96 | } |
||
| 97 | |||
| 98 | if ( $metaData !== [] ) { |
||
| 99 | $location->setVisitedIcon( $this->fileUrlFinder->getUrlForFileName( array_shift( $metaData ) ) ) ; |
||
| 100 | } |
||
| 101 | |||
| 102 | return $location; |
||
| 103 | } |
||
| 104 | |||
| 150 |