| Conditions | 1 |
| Paths | 1 |
| Total Lines | 58 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 46 | public function setupRules() |
||
| 47 | { |
||
| 48 | $this->rules->addMany([ |
||
| 49 | 'string.single' => new Rule(new SubStringMatcher('\''), [ |
||
| 50 | 'context' => ['!keyword.escape', '!comment', '!string', '!keyword.nowdoc'], |
||
| 51 | 'factory' => new TokenFactory(ContextualToken::class), |
||
| 52 | ]), |
||
| 53 | |||
| 54 | 'string.double' => new Rule(new SubStringMatcher('"'), [ |
||
| 55 | 'context' => ['!keyword.escape', '!comment', '!string'], |
||
| 56 | 'factory' => new TokenFactory(ContextualToken::class), |
||
| 57 | ]), |
||
| 58 | 'variable.property' => new Rule(new RegexMatcher('/(?=(?:\w|\)|\])\s*\.([a-z_]\w*))/i'), [ |
||
| 59 | 'priority' => -2 |
||
| 60 | ]), |
||
| 61 | |||
| 62 | 'symbol.function' => new Rule(new RegexMatcher('/function\s+([a-z_]\w+)\s*\(/i')), |
||
| 63 | |||
| 64 | 'keyword.escape' => new Rule(new RegexMatcher('/(\\\(?:x[0-9a-fA-F]{1,2}|u\{[0-9a-fA-F]{1,6}\}|[0-7]{1,3}|.))/i'), [ |
||
| 65 | 'context' => ['string'] |
||
| 66 | ]), |
||
| 67 | |||
| 68 | 'comment' => new Rule(new CommentMatcher(['//'], [ |
||
| 69 | ['/*', '*/'] |
||
| 70 | ]), ['priority' => 3]), |
||
| 71 | |||
| 72 | 'call' => new Rule(new RegexMatcher('/(' . self::IDENTIFIER . ')\s*\(/iu'), ['priority' => -1]), |
||
| 73 | |||
| 74 | 'keyword' => new Rule(new WordMatcher([ |
||
| 75 | 'do', 'if', 'in', 'for', 'let', 'new', 'try', 'var', 'case', 'else', 'enum', 'eval', 'false', |
||
| 76 | 'null', 'this', 'true', 'void', 'with', 'break', 'catch', 'class', 'const', 'super', 'throw', |
||
| 77 | 'while', 'yield', 'delete', 'export', 'import', 'public', 'return', 'static', 'switch', |
||
| 78 | 'typeof', 'default', 'extends', 'finally', 'package', 'private', 'continue', 'debugger', |
||
| 79 | 'function', 'arguments', 'interface', 'protected', 'implements', 'instanceof', |
||
| 80 | ]), ['context' => ['!string', '!comment']]), |
||
| 81 | |||
| 82 | 'number' => new Rule(new RegexMatcher('/\b(-?(?:0[0-7]+|0[xX][0-9a-fA-F]+|0b[01]+|\d+))\b/')), |
||
| 83 | |||
| 84 | 'operator.punctuation' => new Rule(new WordMatcher([',', ';'], ['separated' => false]), ['priority' => 0]), |
||
| 85 | 'operator' => new Rule(new RegexMatcher('/(\+{1,2}|-{1,2}|={1,3}|\|{1,2}|&{1,2})/'), ['priority' => 0]), |
||
| 86 | |||
| 87 | 'string.regex' => [ |
||
| 88 | new OpenRule(new RegexMatcher('#(?>[\[=(?:+,!]|^|return|=>|&&|\|\|)\s*(/).*?/#m'), [ |
||
| 89 | 'context' => ['!comment'] |
||
| 90 | ]), |
||
| 91 | new Rule(new RegexMatcher('#\/.*(/[gimuy]{0,5})#m'), [ |
||
| 92 | 'priority' => 1, |
||
| 93 | 'factory' => new TokenFactory(ContextualToken::class), |
||
| 94 | 'context' => ['!keyword.escape', 'string.regex'] |
||
| 95 | ]) |
||
| 96 | ], |
||
| 97 | |||
| 98 | 'variable' => new Rule(new RegexMatcher('/\b(?<!\.)(' . self::IDENTIFIER . ':?)/iu'), [ |
||
| 99 | 'priority' => -1, |
||
| 100 | 'enabled' => $this->variables |
||
| 101 | ]) |
||
| 102 | ]); |
||
| 103 | } |
||
| 104 | |||
| 110 |