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