Conditions | 10 |
Paths | 97 |
Total 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 |
||
55 | public function parse( $value ) { |
||
56 | $separator = '~'; |
||
57 | |||
58 | $metaData = explode( $separator, $value ); |
||
59 | |||
60 | $coordinatesOrAddress = array_shift( $metaData ); |
||
61 | $coordinates = $this->geocoder->geocode( $coordinatesOrAddress ); |
||
62 | |||
63 | if ( $coordinates === null ) { |
||
64 | throw new ParseException( 'Location is not a parsable coordinate and not a geocodable address' ); |
||
65 | } |
||
66 | |||
67 | $location = new Location( $coordinates ); |
||
68 | |||
69 | if ( $metaData !== [] ) { |
||
70 | $this->setTitleOrLink( $location, array_shift( $metaData ) ); |
||
71 | } else { |
||
72 | if ( $this->useAddressAsTitle && $this->isAddress( $coordinatesOrAddress ) ) { |
||
73 | $location->setTitle( $coordinatesOrAddress ); |
||
74 | } |
||
75 | } |
||
76 | |||
77 | if ( $metaData !== [] ) { |
||
78 | $location->setText( array_shift( $metaData ) ); |
||
79 | } |
||
80 | |||
81 | if ( $metaData !== [] ) { |
||
82 | // FIXME: global access |
||
83 | $location->setIcon( MapsMapper::getFileUrl( array_shift( $metaData ) ) ); |
||
|
|||
84 | } |
||
85 | |||
86 | if ( $metaData !== [] ) { |
||
87 | $location->setGroup( array_shift( $metaData ) ); |
||
88 | } |
||
89 | |||
90 | if ( $metaData !== [] ) { |
||
91 | $location->setInlineLabel( array_shift( $metaData ) ); |
||
92 | } |
||
93 | |||
94 | if ( $metaData !== [] ) { |
||
95 | // FIXME: global access |
||
96 | $location->setVisitedIcon( MapsMapper::getFileUrl( array_shift( $metaData ) ) ) ; |
||
97 | } |
||
98 | |||
99 | return $location; |
||
100 | } |
||
101 | |||
147 |
This method has been deprecated.