| Conditions | 1 |
| Paths | 1 |
| Total Lines | 86 |
| Code Lines | 51 |
| 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 |
||
| 39 | public function setupRules() |
||
| 40 | { |
||
| 41 | $identifier = '-?[_a-zA-Z]+[_a-zA-Z0-9-]*'; |
||
| 42 | $at = [ |
||
| 43 | 'charset', 'import', 'namespace', |
||
| 44 | 'media', 'supports', 'document', 'page', 'font-face', 'keyframes', 'viewport', 'counter-style', |
||
| 45 | 'font-feature-values', 'swash', 'ornaments', 'annotation', 'stylistic', 'styleset', 'character-variant' |
||
| 46 | ]; |
||
| 47 | |||
| 48 | $this->rules->addMany([ |
||
| 49 | 'meta.declaration' => [ |
||
| 50 | new OpenRule(new SubStringMatcher('{'), [ |
||
| 51 | 'context' => ['!meta.declaration.media', '!comment'], |
||
| 52 | 'factory' => new TokenFactory(MetaToken::class) |
||
| 53 | ]), |
||
| 54 | new CloseRule(new SubStringMatcher('}')), |
||
| 55 | ], |
||
| 56 | |||
| 57 | 'meta.declaration.media' => [ |
||
| 58 | new Rule(new RegexMatcher('/@media(.*?\{)/'), [ |
||
| 59 | 'context' => Validator::everywhere(), |
||
| 60 | 'factory' => new TokenFactory(MetaToken::class) |
||
| 61 | ]), |
||
| 62 | ], |
||
| 63 | |||
| 64 | 'meta.declaration.rule' => [ |
||
| 65 | new OpenRule(new RegexMatcher('/@media.*(\()/'), [ |
||
| 66 | 'context' => ['meta.declaration.media'], |
||
| 67 | 'factory' => new TokenFactory(MetaToken::class) |
||
| 68 | ]), |
||
| 69 | new CloseRule(new SubStringMatcher(')')), |
||
| 70 | ], |
||
| 71 | |||
| 72 | 'keyword.at-rule' => new Rule(new RegexMatcher('/(@(?:-[a-z]+-)?(?:'.implode('|', $at).'))/'), [ |
||
| 73 | 'priority' => 2 |
||
| 74 | ]), |
||
| 75 | |||
| 76 | 'string.single' => new Rule(new SubStringMatcher('\''), [ |
||
| 77 | 'context' => $this->everywhere(), |
||
| 78 | 'factory' => new TokenFactory(ContextualToken::class), |
||
| 79 | ]), |
||
| 80 | |||
| 81 | 'string.double' => new Rule(new SubStringMatcher('"'), [ |
||
| 82 | 'context' => $this->everywhere(), |
||
| 83 | 'factory' => new TokenFactory(ContextualToken::class), |
||
| 84 | ]), |
||
| 85 | |||
| 86 | 'symbol.selector.id' => new Rule(new RegexMatcher("/(#$identifier)/i")), |
||
| 87 | 'symbol.selector.tag' => new Rule(new RegexMatcher('/(?>[\s}]|^)(?=(\w+)[^;]*\{)/ms')), |
||
| 88 | 'symbol.selector.class' => new Rule(new RegexMatcher("/(\\.$identifier)/i")), |
||
| 89 | |||
| 90 | 'symbol.selector.class.pseudo' => new Rule(new RegexMatcher("/(:{1,2}$identifier)/")), |
||
| 91 | |||
| 92 | 'number' => new Rule(new RegexMatcher("/([-+]?[0-9]*\\.?[0-9]+([\\w%]+)?)/"), [ |
||
| 93 | 'context' => ['meta.declaration', '!constant.color', '!comment', '!symbol', '!comment', '!string'], |
||
| 94 | 'priority' => 0 |
||
| 95 | ]), |
||
| 96 | |||
| 97 | 'symbol.property' => new Rule(new RegexMatcher("/($identifier:)/"), [ |
||
| 98 | 'context' => ['meta.declaration', '!symbol', '!comment'], |
||
| 99 | 'priority' => 0 |
||
| 100 | ]), |
||
| 101 | |||
| 102 | 'call' => new Rule(new RegexMatcher("/($identifier)\\s*\\((?:(?P<string>[a-z].*?)|.*?)\\)/", [ |
||
| 103 | 1 => Token::NAME, |
||
| 104 | 'string' => 'string.argument' |
||
| 105 | ]), [ |
||
| 106 | 'context' => ['meta.declaration', '!comment', '!string', '!keyword'] |
||
| 107 | ]), |
||
| 108 | |||
| 109 | 'constant.color' => new Rule(new RegexMatcher("/(#[0-9a-f]{3,6})/i"), [ |
||
| 110 | 'priority' => 2, |
||
| 111 | 'context' => ['meta.declaration', '!symbol.color', '!comment'] |
||
| 112 | ]), |
||
| 113 | |||
| 114 | 'operator' => new Rule(new WordMatcher(['>', '+', '*', '!important'], ['separated' => false]), [ |
||
| 115 | 'context' => $this->everywhere() |
||
| 116 | ]), |
||
| 117 | |||
| 118 | 'operator.punctuation' => new Rule(new SubStringMatcher(';', ['separated' => false]), [ |
||
|
|
|||
| 119 | 'context' => $this->everywhere() |
||
| 120 | ]), |
||
| 121 | |||
| 122 | 'comment' => new Rule(new CommentMatcher([], [['/*', '*/']]), ['context' => $this->everywhere()]) |
||
| 123 | ]); |
||
| 124 | } |
||
| 125 | |||
| 145 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.