| Conditions | 1 |
| Paths | 1 |
| Total Lines | 85 |
| Code Lines | 52 |
| 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 |
||
| 36 | public function getRules() |
||
| 37 | { |
||
| 38 | return [ |
||
| 39 | 'string.single' => new Rule(new SubStringMatcher('\''), [ |
||
| 40 | 'context' => ['!keyword.escape', '!comment', '!string'], |
||
| 41 | 'factory' => new TokenFactory(ContextualToken::class), |
||
| 42 | ]), |
||
| 43 | |||
| 44 | 'string.double' => new Rule(new SubStringMatcher('"'), [ |
||
| 45 | 'context' => ['!keyword.escape', '!comment', '!string'], |
||
| 46 | 'factory' => new TokenFactory(ContextualToken::class), |
||
| 47 | ]), |
||
| 48 | |||
| 49 | 'variable' => [ |
||
| 50 | new Rule(new RegexMatcher('/[^\^](\$(?P<namespace>\w+:)?[a-z_]\w*)/i'), [ |
||
| 51 | 'context' => ['!string.single', '!comment'], |
||
| 52 | 'priority' => 0 |
||
| 53 | ]), |
||
| 54 | new Rule(new RegexMatcher('/[^\^](\$\{(?P<namespace>\w+:)?[a-z_]\w*\})/i'), [ |
||
| 55 | 'context' => ['!string.single', '!comment'], |
||
| 56 | 'priority' => 0 |
||
| 57 | ]), |
||
| 58 | ], |
||
| 59 | |||
| 60 | 'variable.splat' => new Rule(new RegexMatcher('/[^\^](\@(?P<namespace>\w+:)?[a-z_]\w*)/i'), [ |
||
| 61 | 'context' => ['!string.single', '!comment'], |
||
| 62 | 'priority' => 0 |
||
| 63 | ]), |
||
| 64 | |||
| 65 | 'variable.special' => new Rule(new RegexMatcher('/(\$(?:\$|\^|\?|_|true|false|null))/i'), [ |
||
| 66 | 'priority' => 5, |
||
| 67 | 'context' => ['!string.single', '!comment'] |
||
| 68 | ]), |
||
| 69 | |||
| 70 | 'variable.scope' => new Rule(null, ['context' => ['*variable']]), |
||
| 71 | |||
| 72 | 'comment' => new Rule(new CommentMatcher(['#'], [['<#', '#>']])), |
||
| 73 | 'keyword.doc-section' => new Rule(new RegexMatcher('/[\s\n](\.\w+)/i'), [ |
||
| 74 | 'context' => ['comment'] |
||
| 75 | ]), |
||
| 76 | |||
| 77 | 'symbol.dotnet' => new Rule(new RegexMatcher('/\[([\w\.]+(?:\[\])?)\]/si')), |
||
| 78 | |||
| 79 | 'annotation' => new Rule( |
||
| 80 | new RegexMatcher('/\[([\w\.]+)\s*(?P<arguments>\((?>[^()]+|(?&arguments))*\))\s*\]/si', [ |
||
| 81 | 1 => Token::NAME, |
||
| 82 | 'arguments' => '$.arguments' |
||
| 83 | ]) |
||
| 84 | ), |
||
| 85 | |||
| 86 | 'keyword' => new Rule(new WordMatcher([ |
||
| 87 | 'Begin', 'Break', 'Catch', 'Continue', 'Data', 'Do', 'DynamicParam', |
||
| 88 | 'Else', 'Elseif', 'End', 'Exit', 'Filter', 'Finally', 'For', 'ForEach', |
||
| 89 | 'From', 'Function', 'If', 'In', 'InlineScript', 'Hidden', 'Parallel', 'Param', |
||
| 90 | 'Process', 'Return', 'Sequence', 'Switch', 'Throw', 'Trap', 'Try', 'Until', 'While', 'Workflow' |
||
| 91 | ]), ['priority' => 3]), |
||
| 92 | |||
| 93 | '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'), [ |
||
| 94 | 'context' => ['!string', '!comment'] |
||
| 95 | ]), |
||
| 96 | |||
| 97 | 'parameter' => new Rule(new RegexMatcher('/\s(-\w+:?)\b/i'), [ |
||
| 98 | 'priority' => 0, |
||
| 99 | 'context' => ['!string', '!comment', '!call'] |
||
| 100 | ]), |
||
| 101 | |||
| 102 | 'operator.punctuation' => new Rule(new WordMatcher([',', ';', '.', '::', '%'], ['separated' => false]), [ |
||
| 103 | 'priority' => 0, |
||
| 104 | 'context' => ['!string', '!comment', '!call'] |
||
| 105 | ]), |
||
| 106 | |||
| 107 | 'number' => [ |
||
| 108 | new Rule(new RegexMatcher('/(-?(?:0x[0-9a-f]+|\d+)l?(?:kb|mb|gb|tb|pb)?)/i'), [ |
||
| 109 | 'priority' => 0, |
||
| 110 | 'context' => ['!string', '!comment', '!variable', '!call'] |
||
| 111 | ]), |
||
| 112 | new Rule(new RegexMatcher('/(-?(?>\d+)?\.\d+(?>d|l)(?>e(?:\+|-)?\d+)?(?:kb|mb|gb|tb|pb)?)/i'), [ |
||
| 113 | 'priority' => 0, |
||
| 114 | 'context' => ['!string', '!comment', '!variable', '!call'] |
||
| 115 | ]) |
||
| 116 | ], |
||
| 117 | |||
| 118 | 'call' => new Rule(new RegexMatcher('/(?<![^`]`)(?<=\n|\{|\(|\}|\||=|;|^|function|filter)\s*(\w[\w-\.]+)/i'), ['priority' => 2]) |
||
| 119 | ]; |
||
| 120 | } |
||
| 121 | |||
| 131 | } |