| Conditions | 16 |
| Paths | 12 |
| Total Lines | 52 |
| Code Lines | 29 |
| 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 |
||
| 87 | private static function parseAttributesRealSwitch(array $attrArr, string &$attrStr = ''): string |
||
| 88 | { |
||
| 89 | foreach ($attrArr as $attr => $val) { |
||
| 90 | |||
| 91 | switch (true) { |
||
| 92 | // don't add empty strings or null values |
||
| 93 | case ('' === $val && 'value' !== $attr || null === $val): |
||
| 94 | break; |
||
| 95 | |||
| 96 | // simple attribute |
||
| 97 | case (is_string($val) || is_numeric($val)): |
||
| 98 | $attrStr .= static::renderAttribute($attr, $val); |
||
| 99 | break; |
||
| 100 | |||
| 101 | // support interface for defining custom parsing schemes |
||
| 102 | case ($val instanceof HtmlAttributeInterface): |
||
| 103 | $attrStr .= static::renderAttribute($attr, $val->parse()); |
||
| 104 | break; |
||
| 105 | |||
| 106 | // boolean attribute |
||
| 107 | case ($val === true): |
||
| 108 | $attrStr .= static::renderAttribute($attr, $attr); |
||
| 109 | break; |
||
| 110 | |||
| 111 | // treat numerical keys as boolean values |
||
| 112 | case (is_int($attr)): |
||
| 113 | $attrStr .= static::renderAttribute($val, $val); |
||
| 114 | break; |
||
| 115 | |||
| 116 | // support for passing an array of boolean values |
||
| 117 | case ('@bool' === $attr): |
||
| 118 | foreach ((array) $val as $bool) { |
||
| 119 | $attrStr .= static::renderAttribute($bool, $bool); |
||
| 120 | } |
||
| 121 | break; |
||
| 122 | |||
| 123 | // support for converting indexed array to DOMTokenList |
||
| 124 | case (is_array($val) && isset($val[0])): |
||
| 125 | $val = implode(' ', array_filter($val)); |
||
| 126 | $attrStr .= static::renderAttribute($attr, $val); |
||
| 127 | break; |
||
| 128 | |||
| 129 | // support for converting associative array to DOMStringMap |
||
| 130 | case (is_array($val)): |
||
| 131 | foreach ($val as $set => $setval) { |
||
| 132 | static::parseAttributesRealSwitch(["{$attr}-{$set}" => $setval], $attrStr); |
||
| 133 | } |
||
| 134 | break; |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | return $attrStr; |
||
| 139 | } |
||
| 234 |