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