| Conditions | 26 |
| Paths | 85 |
| Total Lines | 77 |
| Code Lines | 62 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 104 | private function parseDateFormat( $format ) { |
||
| 105 | $length = strlen( $format ); |
||
| 106 | $numberPattern = '[' . $this->getNumberCharacters() . ']'; |
||
| 107 | $pattern = ''; |
||
| 108 | |||
| 109 | for ( $p = 0; $p < $length; $p++ ) { |
||
| 110 | $code = $format[$p]; |
||
| 111 | |||
| 112 | if ( $code === 'x' && $p < $length - 1 ) { |
||
| 113 | $code .= $format[++$p]; |
||
| 114 | } |
||
| 115 | |||
| 116 | if ( preg_match( '<^x[ijkmot]$>', $code ) && $p < $length - 1 ) { |
||
| 117 | $code .= $format[++$p]; |
||
| 118 | } |
||
| 119 | |||
| 120 | switch ( $code ) { |
||
| 121 | case 'Y': |
||
| 122 | $pattern .= '(?P<year>' . $numberPattern . '+)\p{Z}*'; |
||
| 123 | break; |
||
| 124 | case 'F': |
||
| 125 | case 'm': |
||
| 126 | case 'M': |
||
| 127 | case 'n': |
||
| 128 | case 'xg': |
||
| 129 | $pattern .= '(?P<month>' . $numberPattern . '{1,2}' |
||
| 130 | . $this->getMonthNamesPattern() |
||
| 131 | . ')\p{P}*\p{Z}*'; |
||
| 132 | break; |
||
| 133 | case 'd': |
||
| 134 | case 'j': |
||
| 135 | $pattern .= '(?P<day>' . $numberPattern . '{1,2})\p{P}*\p{Z}*'; |
||
| 136 | break; |
||
| 137 | case 'G': |
||
| 138 | case 'H': |
||
| 139 | $pattern .= '(?P<hour>' . $numberPattern . '{1,2})\p{Z}*'; |
||
| 140 | break; |
||
| 141 | case 'i': |
||
| 142 | $pattern .= '(?P<minute>' . $numberPattern . '{1,2})\p{Z}*'; |
||
| 143 | break; |
||
| 144 | case 's': |
||
| 145 | $pattern .= '(?P<second>' . $numberPattern . '{1,2})\p{Z}*'; |
||
| 146 | break; |
||
| 147 | case '\\': |
||
| 148 | if ( $p < $length - 1 ) { |
||
| 149 | $pattern .= preg_quote( $format[++$p] ); |
||
| 150 | } else { |
||
| 151 | $pattern .= '\\'; |
||
| 152 | } |
||
| 153 | break; |
||
| 154 | case '"': |
||
| 155 | $endQuote = strpos( $format, '"', $p + 1 ); |
||
| 156 | if ( $endQuote !== false ) { |
||
| 157 | $pattern .= preg_quote( substr( $format, $p + 1, $endQuote - $p - 1 ) ); |
||
| 158 | $p = $endQuote; |
||
| 159 | } else { |
||
| 160 | $pattern .= '"'; |
||
| 161 | } |
||
| 162 | break; |
||
| 163 | case 'xn': |
||
| 164 | case 'xN': |
||
| 165 | // We can ignore raw and raw toggle when parsing, because we always accept |
||
| 166 | // canonical digits. |
||
| 167 | break; |
||
| 168 | default: |
||
| 169 | if ( preg_match( '<^\p{P}+$>u', $format[$p] ) ) { |
||
| 170 | $pattern .= '\p{P}*'; |
||
| 171 | } elseif ( preg_match( '<^\p{Z}+$>u', $format[$p] ) ) { |
||
| 172 | $pattern .= '\p{Z}*'; |
||
| 173 | } else { |
||
| 174 | $pattern .= preg_quote( $format[$p] ); |
||
| 175 | } |
||
| 176 | } |
||
| 177 | } |
||
| 178 | |||
| 179 | return $pattern; |
||
| 180 | } |
||
| 181 | |||
| 265 |