| Conditions | 1 |
| Paths | 1 |
| Total Lines | 88 |
| Code Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 2 | 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 setupRules() |
||
| 37 | { |
||
| 38 | $identifier = '-?[_a-zA-Z]+[_a-zA-Z0-9-]*'; |
||
| 39 | $at = [ |
||
| 40 | 'charset', 'import', 'namespace', |
||
| 41 | 'media', 'supports', 'document', 'page', 'font-face', 'keyframes', 'viewport', 'counter-style', |
||
| 42 | 'font-feature-values', 'swash', 'ornaments', 'annotation', 'stylistic', 'styleset', 'character-variant' |
||
| 43 | ]; |
||
| 44 | |||
| 45 | $this->rules->addMany([ |
||
| 46 | 'string' => CommonFeatures::strings(['single' => '\'', 'double' => '"'], [ |
||
| 47 | 'context' => $this->everywhere() |
||
| 48 | ]), |
||
| 49 | |||
| 50 | 'meta.declaration' => [ |
||
| 51 | new OpenRule(new SubStringMatcher('{'), [ |
||
| 52 | 'context' => ['!meta.declaration.media', '!comment'], |
||
| 53 | 'factory' => new TokenFactory(MetaToken::class) |
||
| 54 | ]), |
||
| 55 | new CloseRule(new SubStringMatcher('}')), |
||
| 56 | ], |
||
| 57 | |||
| 58 | 'meta.declaration.media' => [ |
||
| 59 | new Rule(new RegexMatcher('/@media(.*?\{)/'), [ |
||
| 60 | 'context' => Validator::everywhere(), |
||
| 61 | 'factory' => new TokenFactory(MetaToken::class) |
||
| 62 | ]), |
||
| 63 | ], |
||
| 64 | |||
| 65 | 'meta.declaration.rule' => [ |
||
| 66 | new OpenRule(new RegexMatcher('/@media.*(\()/'), [ |
||
| 67 | 'context' => ['meta.declaration.media'], |
||
| 68 | 'factory' => new TokenFactory(MetaToken::class) |
||
| 69 | ]), |
||
| 70 | new CloseRule(new SubStringMatcher(')')), |
||
| 71 | ], |
||
| 72 | |||
| 73 | 'keyword.at-rule' => new Rule(new RegexMatcher('/(@(?:-[a-z]+-)?(?:'.implode('|', $at).'))/'), [ |
||
| 74 | 'priority' => 2 |
||
| 75 | ]), |
||
| 76 | |||
| 77 | 'symbol.selector.id' => new Rule(new RegexMatcher("/(#$identifier)/i")), |
||
| 78 | 'symbol.selector.tag' => new Rule(new RegexMatcher('/(?>[\s}]|^)(?=(\w+)[^;]*\{)/ms')), |
||
| 79 | 'symbol.selector.class' => new Rule(new RegexMatcher("/(\\.$identifier)/i")), |
||
| 80 | |||
| 81 | 'symbol.selector.class.pseudo' => new Rule(new RegexMatcher("/(:{1,2}$identifier)/")), |
||
| 82 | |||
| 83 | 'number' => new Rule(new RegexMatcher("/([-+]?[0-9]*\\.?[0-9]+([\\w%]+)?)/"), [ |
||
| 84 | 'context' => ['meta.declaration', '!constant.color', '!comment', '!symbol', '!comment', '!string'], |
||
| 85 | 'priority' => 0 |
||
| 86 | ]), |
||
| 87 | |||
| 88 | 'symbol.property' => new Rule(new RegexMatcher("/($identifier:)/"), [ |
||
| 89 | 'context' => ['meta.declaration', '!symbol', '!comment'], |
||
| 90 | 'priority' => 2 |
||
| 91 | ]), |
||
| 92 | |||
| 93 | 'call' => new Rule(new RegexMatcher("/($identifier)\\s*\\((?:(?P<string>[a-z].*?)|.*?)\\)/", [ |
||
| 94 | 1 => Token::NAME, |
||
| 95 | 'string' => 'string.argument' |
||
| 96 | ]), [ |
||
| 97 | 'context' => ['meta.declaration', '!comment', '!string', '!keyword'] |
||
| 98 | ]), |
||
| 99 | |||
| 100 | 'constant.color' => [ |
||
| 101 | new Rule(new RegexMatcher("/(#[0-9a-f]{3,6})/i"), [ |
||
| 102 | 'priority' => 2, |
||
| 103 | 'context' => ['meta.declaration', '!comment'] |
||
| 104 | ]), |
||
| 105 | new Rule(new WordMatcher([ |
||
| 106 | 'white', 'silver', 'gray', 'black', 'red', 'maroon', 'yellow', 'olive', |
||
| 107 | 'lime', 'green', 'aqua', 'teal', 'blue', 'navy', 'fuchsia', 'purple' |
||
| 108 | ]), [ |
||
| 109 | 'context' => ['meta.declaration', '!comment', '!symbol', '!variable'] |
||
| 110 | ]), |
||
| 111 | ], |
||
| 112 | |||
| 113 | 'operator' => new Rule(new WordMatcher(['>', '+', '*', '!important'], ['separated' => false]), [ |
||
| 114 | 'context' => $this->everywhere() |
||
| 115 | ]), |
||
| 116 | |||
| 117 | 'operator.punctuation' => new Rule(new SubStringMatcher(';'), [ |
||
| 118 | 'context' => $this->everywhere() |
||
| 119 | ]), |
||
| 120 | |||
| 121 | 'comment' => new Rule(new CommentMatcher([], [['/*', '*/']]), ['context' => $this->everywhere()]) |
||
| 122 | ]); |
||
| 123 | } |
||
| 124 | |||
| 153 |