| Conditions | 1 |
| Paths | 1 |
| Total Lines | 69 |
| Code Lines | 48 |
| 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 |
||
| 35 | public function setupRules() |
||
| 36 | { |
||
| 37 | $function = '[a-z]\w*[!?]?'; |
||
| 38 | $this->rules->addMany([ |
||
| 39 | 'comment' => [ |
||
| 40 | new Rule(new CommentMatcher(['#']), ['context' => ['!string.regex', '!string']]), |
||
| 41 | 'doc' => [ |
||
| 42 | new OpenRule(new RegexMatcher('/^(=begin)/m')), |
||
| 43 | new CloseRule(new RegexMatcher('/^(=end)/m')), |
||
| 44 | ] |
||
| 45 | ], |
||
| 46 | 'keyword' => new Rule(new WordMatcher([ |
||
| 47 | 'BEGIN', 'class', 'ensure', 'when', 'END', 'def', 'not', 'super', 'while', |
||
| 48 | 'alias', 'defined', 'for', 'or', 'then', 'yield', 'and', 'do', 'if', 'redo', 'begin', 'else', |
||
| 49 | 'in', 'rescue', 'undef', 'break', 'elsif', 'module', 'retry', 'unless', 'case', 'end', 'next', 'return', |
||
| 50 | 'until', |
||
| 51 | ], ['case-sensitivity' => true])), |
||
| 52 | 'string' => [ |
||
| 53 | CommonFeatures::strings( |
||
| 54 | ['single' => '\'', 'double' => '"'], |
||
| 55 | ['context' => ['!operator.escape', '!comment', '!string', '!expression']] |
||
| 56 | ), |
||
| 57 | 'generalized' => [ |
||
| 58 | // TODO: Generalized strings |
||
| 59 | ] |
||
| 60 | ], |
||
| 61 | 'operator.escape' => new Rule(new RegexMatcher('/(\\\.)/'), [ |
||
| 62 | 'context' => ['string'] |
||
| 63 | ]), |
||
| 64 | 'constant' => [ |
||
| 65 | new Rule(new RegexMatcher('/(?:[a-z_])?::([a-z_]\w*)/i')), |
||
| 66 | 'special' => new Rule(new WordMatcher(['self', 'nil', 'true', 'false', '__FILE__', '__LINE__'])) |
||
| 67 | ], |
||
| 68 | 'variable' => [ |
||
| 69 | 'global' => new Rule(new RegexMatcher('/(?:[^\\\]|^)(\$\w*)/i')), |
||
| 70 | 'property' => new Rule(new RegexMatcher('/(?:[^\\\]|^)(@{1,2}\w*)/i')), |
||
| 71 | ], |
||
| 72 | // JS + Perl = Ruby? |
||
| 73 | 'string.regex' => [ |
||
| 74 | new OpenRule(new RegexMatcher('#(?>[\[=(?:+,!~]|^|return|=>|&&|\|\|)\s*(/).*?/#sm'), [ |
||
| 75 | 'context' => ['!comment'] |
||
| 76 | ]), |
||
| 77 | new Rule(new RegexMatcher('#(?=\/.*?(/[mixounse]*))#sm'), [ |
||
| 78 | 'priority' => 2, |
||
| 79 | 'factory' => new TokenFactory(ContextualToken::class), |
||
| 80 | 'context' => ['!operator.escape', 'string.regex'] |
||
| 81 | ]) |
||
| 82 | ], |
||
| 83 | 'call' => [ |
||
| 84 | new Rule(new RegexMatcher("/($function)\\s*\\(/i"), ['priority' => 2]), |
||
| 85 | new Rule(new RegexMatcher( |
||
| 86 | // fixme: expression handling smth[blah].func |
||
| 87 | "/(?<![^\\\\]\\\\)(?<=\\n|\\{|\\(|\\}|\\|\\||or|&&|and|=|;)\\s*(?:\\w+(?:::|\\.))?($function)(?:[\\h\r]*\$|\\h+['\":\\w])/im" |
||
| 88 | ), ['priority' => 0]), |
||
| 89 | ], |
||
| 90 | 'symbol' => [ |
||
| 91 | 'symbol' => new Rule(new RegexMatcher('/[^\B:](:[a-z_]\w*)/i')), |
||
| 92 | 'class' => new Rule(new RegexMatcher('/class\s+([a-z_]\w*)/i')), |
||
| 93 | 'function' => new Rule(new RegexMatcher('/def\s+(?:\[\]\s*|\*\s*|\w+\.){0,2}([a-z_]\w*)/i')), |
||
| 94 | ], |
||
| 95 | 'expression.in-string' => new Rule(new RegexMatcher('/(?=(\#\{((?>[^\#{}]+|(?1))+)\}))/x'), [ |
||
| 96 | 'context' => ['string.double'], |
||
| 97 | 'factory' => new TokenFactory(LanguageToken::class), |
||
| 98 | 'inject' => $this |
||
| 99 | ]), |
||
| 100 | |||
| 101 | 'number' => new Rule(new RegexMatcher('/((?:-|\b)(?:0[0-7]+|0[xX][0-9a-fA-F]+|0b[01]+|\d+))/')), |
||
| 102 | ]); |
||
| 103 | } |
||
| 104 | |||
| 115 |