| Conditions | 13 |
| Paths | 13 |
| Total Lines | 45 |
| Code Lines | 25 |
| 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 |
||
| 30 | public function buildHtmlAttributes() |
||
| 31 | { |
||
| 32 | $html = ''; |
||
| 33 | |||
| 34 | foreach ($this->htmlAttributes as $name => $value) { |
||
| 35 | if (is_bool($value)) { |
||
| 36 | if ($value) { |
||
| 37 | $html .= " $name"; |
||
| 38 | } |
||
| 39 | continue; |
||
| 40 | } |
||
| 41 | |||
| 42 | if (is_array($value)) { |
||
| 43 | if (in_array($name, static::$dataAttributes)) { |
||
| 44 | foreach ($value as $n => $v) { |
||
| 45 | if (is_string($v)) { |
||
| 46 | $html .= " $name-$n=\"" . HtmlHelper::encode($v, $this->charset) . '"'; |
||
| 47 | } |
||
| 48 | } |
||
| 49 | continue; |
||
| 50 | } |
||
| 51 | |||
| 52 | if ($name === 'class') { |
||
| 53 | if (empty($value)) { |
||
| 54 | continue; |
||
| 55 | } |
||
| 56 | $html .= " $name=\"" . HtmlHelper::encode(implode(' ', $value), $this->charset) . '"'; |
||
| 57 | continue; |
||
| 58 | } |
||
| 59 | |||
| 60 | if ($name === 'style') { |
||
| 61 | if (empty($value)) { |
||
| 62 | continue; |
||
| 63 | } |
||
| 64 | $html .= " $name=\"" . HtmlHelper::encode(HtmlHelper::cssStyleFromArray($value), $this->charset) . '"'; |
||
| 65 | } |
||
| 66 | continue; |
||
| 67 | } |
||
| 68 | |||
| 69 | if ($value !== null) { |
||
| 70 | $html .= " $name=\"" . HtmlHelper::encode($value, $this->charset) . '"'; |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | return $html; |
||
| 75 | } |
||
| 77 |