| Conditions | 1 |
| Paths | 1 |
| Total Lines | 83 |
| Code Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| 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 |
||
| 30 | public function setupRules() |
||
| 31 | { |
||
| 32 | $this->rules->addMany([ |
||
| 33 | 'string' => CommonFeatures::strings(['single' => '\'', 'double' => '"'], [ |
||
| 34 | 'context' => ['!operator.escape', '!comment', '!string'], |
||
| 35 | ]), |
||
| 36 | |||
| 37 | 'variable' => [ |
||
| 38 | new Rule(new RegexMatcher('/(?<!`)(\$(?P<namespace>\w+:)?[a-z_]\w*)/i'), [ |
||
| 39 | 'context' => ['!string.single', '!comment', '!variable'], |
||
| 40 | 'priority' => 0 |
||
| 41 | ]), |
||
| 42 | new Rule(new RegexMatcher('/[^`](\$\{(?P<namespace>\w+:)?.*?\})/i'), [ |
||
| 43 | 'context' => ['!string.single', '!comment', '!variable'], |
||
| 44 | 'priority' => 0 |
||
| 45 | ]), |
||
| 46 | ], |
||
| 47 | |||
| 48 | 'variable.splat' => new Rule(new RegexMatcher('/[^`](\@(?P<namespace>\w+:)?[a-z_]\w*)/i'), [ |
||
| 49 | 'context' => ['!string.single', '!comment'], |
||
| 50 | 'priority' => 0 |
||
| 51 | ]), |
||
| 52 | |||
| 53 | 'variable.special' => new Rule(new RegexMatcher('/(\$(?:\$|\^|\?|_|true|false|null))\b/i'), [ |
||
| 54 | 'priority' => 5, |
||
| 55 | 'context' => ['!string.single', '!comment'] |
||
| 56 | ]), |
||
| 57 | |||
| 58 | 'variable.scope' => new Rule(null, ['context' => ['*variable']]), |
||
| 59 | |||
| 60 | 'comment' => new Rule(new CommentMatcher(['#'], [['<#', '#>']])), |
||
| 61 | 'keyword.doc-section' => new Rule(new RegexMatcher('/[\s\n](\.\w+)/i'), [ |
||
| 62 | 'context' => ['comment'] |
||
| 63 | ]), |
||
| 64 | |||
| 65 | 'symbol.dotnet' => new Rule(new RegexMatcher('/(\[[a-z][\w\.]*(?:\[\])?\])/si')), |
||
| 66 | |||
| 67 | 'symbol.annotation' => new Rule( |
||
| 68 | new RegexMatcher('/\[([\w\.]+)\s*(?P<arguments>\((?>[^()]+|(?&arguments))*\))\s*\]/si', [ |
||
| 69 | 1 => Token::NAME, |
||
| 70 | 'arguments' => '$.arguments' |
||
| 71 | ]) |
||
| 72 | ), |
||
| 73 | |||
| 74 | 'keyword' => new Rule(new WordMatcher([ |
||
| 75 | 'Begin', 'Break', 'Catch', 'Continue', 'Data', 'Do', 'DynamicParam', |
||
| 76 | 'Else', 'Elseif', 'End', 'Exit', 'Filter', 'Finally', 'For', 'ForEach', |
||
| 77 | 'From', 'Function', 'If', 'In', 'InlineScript', 'Hidden', 'Parallel', 'Param', |
||
| 78 | 'Process', 'Return', 'Sequence', 'Switch', 'Throw', 'Trap', 'Try', 'Until', 'While', 'Workflow' |
||
| 79 | ]), ['priority' => 3]), |
||
| 80 | |||
| 81 | 'operator' => new Rule(new RegexMatcher('/(&|\-eq|\-ne|\-gt|\-ge|\-lt|\-le|\-ieq|\-ine|\-igt|\-ige|\-ilt|\-ile|\-ceq|\-cne|\-cgt|\-cge|\-clt|\-cle|\-like|\-notlike|\-match|\-notmatch|\-ilike|\-inotlike|\-imatch|\-inotmatch|\-clike|\-cnotlike|\-cmatch|\-cnotmatch|\-contains|\-notcontains|\-icontains|\-inotcontains|\-ccontains|\-cnotcontains|\-isnot|\-is|\-as|\-replace|\-ireplace|\-creplace|\-and|\-or|\-band|\-bor|\-not|\-bnot|\-f|\-casesensitive|\-exact|\-file|\-regex|\-wildcard)\b/i'), [ |
||
| 82 | 'context' => ['!string', '!comment'], |
||
| 83 | ]), |
||
| 84 | |||
| 85 | 'symbol.parameter' => new Rule(new RegexMatcher('/\s(-\w+:?)\b/i'), [ |
||
| 86 | 'priority' => 0, |
||
| 87 | 'context' => ['!string', '!comment', '!call'] |
||
| 88 | ]), |
||
| 89 | |||
| 90 | 'operator.punctuation' => new Rule(new WordMatcher([',', ';', '.', '::', '%'], ['separated' => false]), [ |
||
| 91 | 'priority' => 0, |
||
| 92 | 'context' => ['!string', '!comment', '!call'] |
||
| 93 | ]), |
||
| 94 | |||
| 95 | 'number' => [ |
||
| 96 | new Rule(new RegexMatcher('/\b(-?(?:0x[0-9a-f]+|\d+)l?(?:kb|mb|gb|tb|pb)?)\b/i'), [ |
||
| 97 | 'priority' => 0, |
||
| 98 | 'context' => ['!string', '!comment', '!variable', '!call'] |
||
| 99 | ]), |
||
| 100 | new Rule(new RegexMatcher('/\b(-?(?>\d+)?\.\d+(?>d|l)(?>e(?:\+|-)?\d+)?(?:kb|mb|gb|tb|pb)?)\b/i'), [ |
||
| 101 | 'priority' => 0, |
||
| 102 | 'context' => ['!string', '!comment', '!variable', '!call'] |
||
| 103 | ]) |
||
| 104 | ], |
||
| 105 | |||
| 106 | 'call' => new Rule(new RegexMatcher( |
||
| 107 | '/(?<![^`]`)(?<=\n|\{|\(|\}|\||=|;|^|function|filter|^PS>)\s*((?:\w+\\\)?\w[\w-\.]+)/im' |
||
| 108 | ), ['priority' => 2]), |
||
| 109 | |||
| 110 | 'delimiter.prompt' => new Rule(new RegexMatcher('/^(PS>)/im'), ['priority' => 4]), |
||
| 111 | ]); |
||
| 112 | } |
||
| 113 | |||
| 129 |