| Conditions | 1 |
| Paths | 1 |
| Total Lines | 56 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 37 | public function getRules() |
||
| 38 | { |
||
| 39 | $identifier = '[\w-]+'; |
||
| 40 | |||
| 41 | return [ |
||
| 42 | 'declaration' => [ |
||
| 43 | new OpenRule(new SubStringMatcher('{'), ['context' => ['!declaration.media']]), |
||
| 44 | new CloseRule(new SubStringMatcher('}')), |
||
| 45 | ], |
||
| 46 | |||
| 47 | 'declaration.media' => [ |
||
| 48 | new Rule(new RegexMatcher('/@media(.*?\{)/'), ['context' => ['!!']]), |
||
| 49 | ], |
||
| 50 | |||
| 51 | 'declaration.rule' => [ |
||
| 52 | new OpenRule(new SubStringMatcher('('), ['context' => ['declaration.media']]), |
||
| 53 | new CloseRule(new SubStringMatcher(')')), |
||
| 54 | ], |
||
| 55 | |||
| 56 | 'keyword.control-sequence' => new Rule(new RegexMatcher("/(@$identifier)/")), |
||
| 57 | |||
| 58 | 'string.single' => new Rule(new SubStringMatcher('\''), [ |
||
| 59 | 'context' => ['!keyword.escape', '!comment', '!string', '!keyword.nowdoc'], |
||
| 60 | 'factory' => new TokenFactory(ContextualToken::class), |
||
| 61 | ]), |
||
| 62 | |||
| 63 | 'string.double' => new Rule(new SubStringMatcher('"'), [ |
||
| 64 | 'context' => ['!keyword.escape', '!comment', '!string'], |
||
| 65 | 'factory' => new TokenFactory(ContextualToken::class), |
||
| 66 | ]), |
||
| 67 | |||
| 68 | 'symbol.selector.id' => new Rule(new RegexMatcher("/(#$identifier)/")), |
||
| 69 | 'symbol.selector.tag' => new Rule(new RegexMatcher("/(?=(?>\\s|\\/|}|^)(\\w+).*\\{)/")), |
||
| 70 | 'symbol.selector.class' => new Rule(new RegexMatcher("/(\\.$identifier)/")), |
||
| 71 | |||
| 72 | 'symbol.selector.class.pseudo' => new Rule(new RegexMatcher("/(:$identifier)/")), |
||
| 73 | |||
| 74 | 'number' => new Rule(new RegexMatcher("/([-+]?[0-9]*\\.?[0-9]+([\\w%]+)?)/"), [ |
||
| 75 | 'context' => ['declaration', '!constant.color'] |
||
| 76 | ]), |
||
| 77 | 'constant.property' => new Rule(new RegexMatcher("/($identifier):/"), ['context' => ['declaration']]), |
||
| 78 | |||
| 79 | 'call' => new Rule(new RegexMatcher("/($identifier)\\(/"), ['context' => ['!!']]), |
||
| 80 | |||
| 81 | 'constant.color' => new Rule(new RegexMatcher("/(#[0-9a-f]{1,6})/i"), [ |
||
| 82 | 'priority' => 2, |
||
| 83 | 'context' => ['declaration', '!symbol.color'] |
||
| 84 | ]), |
||
| 85 | |||
| 86 | 'operator' => new Rule(new WordMatcher([':', '>', '+', '*', ';', ',', '!important'], ['separated' => false]), [ |
||
| 87 | 'context' => ['!comment'] |
||
| 88 | ]), |
||
| 89 | |||
| 90 | 'comment' => new Rule(new CommentMatcher([], [['/*', '*/']])) |
||
| 91 | ]; |
||
| 92 | } |
||
| 93 | |||
| 103 | } |