| Conditions | 12 |
| Paths | 36 |
| Total Lines | 32 |
| Code Lines | 15 |
| 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 |
||
| 99 | public function getAttributesHTML($attrs = null) |
||
| 100 | { |
||
| 101 | $excludeKeys = (is_string($attrs)) ? func_get_args() : null; |
||
| 102 | |||
| 103 | if (!$attrs || is_string($attrs)) { |
||
| 104 | $attrs = $this->attributes; |
||
| 105 | } |
||
| 106 | |||
| 107 | // Remove empty or excluded values |
||
| 108 | foreach ($attrs as $key => $value) { |
||
| 109 | if (($excludeKeys && in_array($key, $excludeKeys)) |
||
| 110 | || (!$value && $value !== 0 && $value !== '0') |
||
| 111 | ) { |
||
| 112 | unset($attrs[$key]); |
||
| 113 | continue; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | // Create markkup |
||
| 118 | $parts = array(); |
||
| 119 | |||
| 120 | foreach ($attrs as $name => $value) { |
||
| 121 | if ($value === true) { |
||
| 122 | $value = $name; |
||
| 123 | } |
||
| 124 | |||
| 125 | $parts[] = sprintf('%s="%s"', Convert::raw2att($name), Convert::raw2att($value)); |
||
| 126 | } |
||
| 127 | |||
| 128 | /** @var DBHTMLText $fragment */ |
||
| 129 | $fragment = DBField::create_field('HTMLFragment', implode(' ', $parts)); |
||
| 130 | return $fragment; |
||
| 131 | } |
||
| 133 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..