| Conditions | 1 |
| Paths | 1 |
| Total Lines | 64 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 37 | public function setupRules() |
||
| 38 | { |
||
| 39 | $this->rules->addMany([ |
||
| 40 | 'keyword' => new Rule(new WordMatcher([ |
||
| 41 | 'auto', 'break', 'case', 'const', 'continue', 'default', 'do', 'else', 'enum', 'extern', 'for', 'goto', |
||
| 42 | 'if', 'register', 'return', 'sizeof', 'static', 'struct', 'switch', 'typedef', 'union', 'volatile', |
||
| 43 | 'while', |
||
| 44 | ])), |
||
| 45 | |||
| 46 | 'meta.newline' => new CloseRule(new RegexMatcher('/()\r?\n/'), [ |
||
| 47 | 'factory' => new TokenFactory(TerminatorToken::class), |
||
| 48 | 'context' => ['!keyword.escape', '*string', '*call.preprocessor'], |
||
| 49 | 'closes' => ['string.double', 'preprocessor'] |
||
| 50 | ]), |
||
| 51 | |||
| 52 | 'preprocessor' => new OpenRule(new RegexMatcher('/^(#)/m'), [ |
||
| 53 | 'context' => Validator::everywhere() |
||
| 54 | ]), |
||
| 55 | |||
| 56 | 'call' => [ |
||
| 57 | 'preprocessor' => new Rule(new RegexMatcher('/^#\s*(\w+)\b/m'), [ |
||
| 58 | 'context' => ['preprocessor'] |
||
| 59 | ]), |
||
| 60 | new Rule(new RegexMatcher('/([a-z_]\w*)\s*\(/i'), ['priority' => -1]), |
||
| 61 | ], |
||
| 62 | |||
| 63 | 'keyword.escape' => new Rule(new RegexMatcher('/(\\\(?:.|[0-7]{3}|x\x{2}))/'), [ |
||
| 64 | 'context' => Validator::everywhere() |
||
| 65 | ]), |
||
| 66 | |||
| 67 | 'keyword.format' => new Rule( |
||
| 68 | new RegexMatcher('/(%[diuoxXfFeEgGaAcspn%][-+#0]?(?:[0-9]+|\*)?(?:\.(?:[0-9]+|\*))?)/'), [ |
||
| 69 | 'context' => ['string'] |
||
| 70 | ] |
||
| 71 | ), |
||
| 72 | |||
| 73 | 'string' => [ |
||
| 74 | 'double' => new Rule(new SubStringMatcher('"'), [ |
||
| 75 | 'factory' => new TokenFactory(ContextualToken::class), |
||
| 76 | 'context' => ['!comment'] |
||
| 77 | ]), |
||
| 78 | 'single' => new Rule(new SubStringMatcher('\''), [ |
||
| 79 | 'factory' => new TokenFactory(ContextualToken::class) |
||
| 80 | ]), |
||
| 81 | new Rule(new RegexMatcher('/(<.*?>)/'), [ |
||
| 82 | 'context' => ['preprocessor'] |
||
| 83 | ]) |
||
| 84 | ], |
||
| 85 | |||
| 86 | 'symbol.type' => [ |
||
| 87 | new Rule(new RegexMatcher('/(\w+)(?:\s+|\s*\*\s*)\w+\s*[=();,]/')), |
||
| 88 | new Rule(new WordMatcher(['int', 'float', 'double', 'char', 'void', 'long', 'short', 'signed', 'unsigned'])) |
||
| 89 | ], |
||
| 90 | |||
| 91 | 'comment' => [ |
||
| 92 | new Rule(new CommentMatcher(['//'], [['/*', '*/']]), ['priority' => 2]) |
||
| 93 | ], |
||
| 94 | |||
| 95 | 'number' => new Rule(new RegexMatcher('/\b(-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)[ful]*)\b/i')), |
||
| 96 | 'operator' => new Rule(new RegexMatcher('/([*&])/'), [ |
||
| 97 | 'priority' => 0 |
||
| 98 | ]), |
||
| 99 | ]); |
||
| 100 | } |
||
| 101 | |||
| 111 | } |