| Conditions | 11 |
| Paths | 11 |
| Total Lines | 77 |
| Code Lines | 41 |
| 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 |
||
| 19 | public function tokenise($pattern, $expand = false) |
||
| 20 | { |
||
| 21 | preg_match_all(' |
||
| 22 | / |
||
| 23 | (?<class_U_explicit>\\\U) |
||
| 24 | \{ |
||
| 25 | (?<class_U_repetition>[0-9]+) |
||
| 26 | \} |
||
| 27 | | |
||
| 28 | (?<class_U_implicit>\\\U) |
||
| 29 | | |
||
| 30 | \[ |
||
| 31 | (?<range_token_explicit>[^]]+) |
||
| 32 | \] |
||
| 33 | \{ |
||
| 34 | (?<range_repetition>[0-9]+) |
||
| 35 | \} |
||
| 36 | | |
||
| 37 | \[ |
||
| 38 | (?<range_token_implicit>[^]]+) |
||
| 39 | \] |
||
| 40 | | |
||
| 41 | (?<literal_string>[^\\\[]+) |
||
| 42 | /x |
||
| 43 | ', $pattern, $matches, \PREG_SET_ORDER); |
||
| 44 | $tokens = []; |
||
| 45 | foreach ($matches as $match) { |
||
| 46 | |||
| 47 | if (!empty($match['class_U_explicit'])) { |
||
| 48 | $token = [ |
||
| 49 | 'type' => 'class', |
||
| 50 | 'class' => static::CLASS_UPPERCASE_UNAMBIGUOUS, |
||
| 51 | 'repetition' => (int)$match['class_U_repetition'], |
||
| 52 | ]; |
||
| 53 | if ($expand) { |
||
| 54 | $token['haystack'] = 'ABCDEFGHKMNOPRSTUVWXYZ23456789'; |
||
| 55 | } |
||
| 56 | $tokens[] = $token; |
||
| 57 | } elseif (!empty($match['class_U_implicit'])) { |
||
| 58 | $token = [ |
||
| 59 | 'type' => 'class', |
||
| 60 | 'class' => static::CLASS_UPPERCASE_UNAMBIGUOUS, |
||
| 61 | 'repetition' => 1, |
||
| 62 | ]; |
||
| 63 | if ($expand) { |
||
| 64 | $token['haystack'] = 'ABCDEFGHKMNOPRSTUVWXYZ23456789'; |
||
| 65 | } |
||
| 66 | $tokens[] = $token; |
||
| 67 | } elseif (!empty($match['range_token_explicit'])) { |
||
| 68 | $token = [ |
||
| 69 | 'type' => 'range', |
||
| 70 | 'token' => $match['range_token_explicit'], |
||
| 71 | 'repetition' => (int)$match['range_repetition'], |
||
| 72 | ]; |
||
| 73 | if ($expand) { |
||
| 74 | $token['haystack'] = static::expandRange($match['range_token_explicit']); |
||
| 75 | } |
||
| 76 | $tokens[] = $token; |
||
| 77 | } elseif (!empty($match['range_token_implicit'])) { |
||
| 78 | $token = [ |
||
| 79 | 'type' => 'range', |
||
| 80 | 'token' => $match['range_token_implicit'], |
||
| 81 | 'repetition' => 1, |
||
| 82 | ]; |
||
| 83 | if ($expand) { |
||
| 84 | $token['haystack'] = static::expandRange($match['range_token_implicit']); |
||
| 85 | } |
||
| 86 | $tokens[] = $token; |
||
| 87 | } elseif (!empty($match['literal_string'])) { |
||
| 88 | $tokens[] = [ |
||
| 89 | 'type' => 'literal', |
||
| 90 | 'string' => $match['literal_string'], |
||
| 91 | ]; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 95 | return $tokens; |
||
| 96 | } |
||
| 135 |