Conditions | 16 |
Paths | 12 |
Total Lines | 58 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 parseAttributesReal(array $attrArr, string &$attrStr = ''): string |
||
25 | { |
||
26 | foreach ($attrArr as $attr => $val) { |
||
27 | |||
28 | // don't add empty strings or null values |
||
29 | if ('' === $val && 'value' !== $attr || null === $val) { |
||
|
|||
30 | continue; |
||
31 | } |
||
32 | |||
33 | // simple attribute |
||
34 | if (is_string($val) || is_numeric($val)) { |
||
35 | $attrStr .= static::renderAttribute($attr, $val); |
||
36 | continue; |
||
37 | } |
||
38 | |||
39 | // support interface for defining custom parsing schemes |
||
40 | if ($val instanceof HtmlAttributeInterface) { |
||
41 | $attrStr .= static::renderAttribute($attr, $val->parse()); |
||
42 | continue; |
||
43 | } |
||
44 | |||
45 | // boolean attribute |
||
46 | if ($val === true) { |
||
47 | $attrStr .= static::renderAttribute($attr, $attr); |
||
48 | continue; |
||
49 | } |
||
50 | |||
51 | // treat numerical keys as boolean values |
||
52 | if (is_int($attr)) { |
||
53 | $attrStr .= static::renderAttribute($val, $val); |
||
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::renderAttribute($bool, $bool); |
||
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::renderAttribute($attr, $val); |
||
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::parseAttributesReal(["{$attr}-{$set}" => $setval], $attrStr); |
||
76 | } |
||
77 | continue; |
||
78 | } |
||
79 | } |
||
80 | |||
81 | return $attrStr; |
||
82 | } |
||
234 |