| Conditions | 10 |
| Paths | 9 |
| Total Lines | 32 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | 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 |
||
| 58 | protected function stringParse( $value ) { |
||
| 59 | //Matches Year and month separated by a separator, \p{L} matches letters outside the ASCII range |
||
| 60 | if ( !preg_match( '/^(-?[\d\p{L}]+)\s*?[\/\-\s.,]\s*(-?[\d\p{L}]+)$/', trim( $value ), $matches ) ) { |
||
| 61 | throw new ParseException( 'Failed to parse year and month', $value, self::FORMAT_NAME ); |
||
| 62 | } |
||
| 63 | list( , $a, $b ) = $matches; |
||
| 64 | |||
| 65 | $aIsInt = preg_match( '/^-?\d+$/', $a ); |
||
| 66 | $bIsInt = preg_match( '/^-?\d+$/', $b ); |
||
| 67 | |||
| 68 | if ( $aIsInt && $bIsInt ) { |
||
| 69 | if ( $this->canBeMonth( $a ) ) { |
||
| 70 | return $this->getTimeFromYearMonth( $b, $a ); |
||
| 71 | } elseif ( $this->canBeMonth( $b ) ) { |
||
| 72 | return $this->getTimeFromYearMonth( $a, $b ); |
||
| 73 | } |
||
| 74 | } elseif ( $aIsInt ) { |
||
| 75 | $month = $this->parseMonth( $b ); |
||
| 76 | |||
| 77 | if ( $month ) { |
||
|
|
|||
| 78 | return $this->getTimeFromYearMonth( $a, $month ); |
||
| 79 | } |
||
| 80 | } elseif ( $bIsInt ) { |
||
| 81 | $month = $this->parseMonth( $a ); |
||
| 82 | |||
| 83 | if ( $month ) { |
||
| 84 | return $this->getTimeFromYearMonth( $b, $month ); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | throw new ParseException( 'Failed to parse year and month', $value, self::FORMAT_NAME ); |
||
| 89 | } |
||
| 90 | |||
| 130 |
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: