Conditions | 15 |
Paths | 12 |
Total Lines | 58 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
24 | private static function _parseAttributes($attributesArray, $options, &$attrStr = '') |
||
25 | { |
||
26 | foreach ($attributesArray as $attr => $val) { |
||
27 | |||
28 | // don't add empty strings or null values |
||
29 | if ('' === $val || null === $val) { |
||
30 | continue; |
||
31 | } |
||
32 | |||
33 | // simple attribute |
||
34 | if (is_string($val) || is_numeric($val)) { |
||
35 | $attrStr .= static::attribute($attr, $val, true, $options); |
||
36 | continue; |
||
37 | } |
||
38 | |||
39 | // support interface for defining custom parsing schemes |
||
40 | if ($val instanceof HtmlAttributeInterface) { |
||
41 | $attrStr .= static::attribute($attr, $val->parse(), true, $options); |
||
42 | continue; |
||
43 | } |
||
44 | |||
45 | // boolean attribute |
||
46 | if ($val === true) { |
||
47 | $attrStr .= static::attribute($attr, $attr, true, $options); |
||
48 | continue; |
||
49 | } |
||
50 | |||
51 | // treat numerical keys as boolean values |
||
52 | if (is_int($attr)) { |
||
53 | $attrStr .= static::attribute($val, $val, true, $options); |
||
54 | continue; |
||
55 | } |
||
56 | |||
57 | // support for passing an array of boolean values |
||
58 | if ('@boolean' === $attr) { |
||
59 | foreach ((array) $val as $bool) { |
||
60 | $attrStr .= static::attribute($bool, $bool, true, $options); |
||
61 | } |
||
62 | continue; |
||
63 | } |
||
64 | |||
65 | // support for converting indexed array to DOMTokenList |
||
66 | if (is_array($val) && isset($val[0])) { |
||
67 | $val = implode(' ', array_filter($val)); |
||
68 | $attrStr .= static::attribute($attr, $val, true, $options); |
||
69 | continue; |
||
70 | } |
||
71 | |||
72 | // support for converting associative array to DOMStringMap |
||
73 | if (is_array($val)) { |
||
74 | foreach ($val as $set => $setval) { |
||
75 | static::_parseAttributes(["{$attr}-{$set}" => $setval], $options, $attrStr); |
||
76 | } |
||
77 | continue; |
||
78 | } |
||
79 | } |
||
80 | |||
81 | return ltrim(($attrStr)); |
||
82 | } |
||
165 |
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. Please note the @ignore annotation hint above.