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