| Conditions | 10 | 
| Paths | 9 | 
| Total Lines | 33 | 
| Code Lines | 20 | 
| 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 | 	protected function stringParse( $value ) { | 
            ||
| 61 | // Matches year and month separated by a separator.  | 
            ||
| 62 | 		// \p{L} matches letters outside the ASCII range. | 
            ||
| 63 | 		if ( !preg_match( '/^(-?[\d\p{L}]+)\s*?[\/\-\s.,]\s*(-?[\d\p{L}]+)$/', trim( $value ), $matches ) ) { | 
            ||
| 64 | throw new ParseException( 'Failed to parse year and month', $value, self::FORMAT_NAME );  | 
            ||
| 65 | }  | 
            ||
| 66 | list( , $a, $b ) = $matches;  | 
            ||
| 67 | |||
| 68 | $aIsInt = preg_match( '/^-?\d+$/', $a );  | 
            ||
| 69 | $bIsInt = preg_match( '/^-?\d+$/', $b );  | 
            ||
| 70 | |||
| 71 | 		if ( $aIsInt && $bIsInt ) { | 
            ||
| 72 | 			if ( $this->canBeMonth( $a ) ) { | 
            ||
| 73 | return $this->getTimeFromYearMonth( $b, $a );  | 
            ||
| 74 | 			} elseif ( $this->canBeMonth( $b ) ) { | 
            ||
| 75 | return $this->getTimeFromYearMonth( $a, $b );  | 
            ||
| 76 | }  | 
            ||
| 77 | 		} elseif ( $aIsInt ) { | 
            ||
| 78 | $month = $this->parseMonth( $b );  | 
            ||
| 79 | |||
| 80 | 			if ( $month ) { | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 81 | return $this->getTimeFromYearMonth( $a, $month );  | 
            ||
| 82 | }  | 
            ||
| 83 | 		} elseif ( $bIsInt ) { | 
            ||
| 84 | $month = $this->parseMonth( $a );  | 
            ||
| 85 | |||
| 86 | 			if ( $month ) { | 
            ||
| 87 | return $this->getTimeFromYearMonth( $b, $month );  | 
            ||
| 88 | }  | 
            ||
| 89 | }  | 
            ||
| 90 | |||
| 91 | throw new ParseException( 'Failed to parse year and month', $value, self::FORMAT_NAME );  | 
            ||
| 92 | }  | 
            ||
| 93 | |||
| 133 | 
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: