| Conditions | 14 |
| Paths | 1808 |
| Total Lines | 50 |
| Code Lines | 31 |
| 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 |
||
| 111 | public function __toString() |
||
| 112 | { |
||
| 113 | $buffer = []; |
||
| 114 | try { |
||
| 115 | |||
| 116 | if (!empty($this->ns)) { |
||
| 117 | $buffer[] = $this->ns; |
||
| 118 | $buffer[] = '|'; |
||
| 119 | } |
||
| 120 | if (!empty($this->element)) { |
||
| 121 | $buffer[] = $this->element; |
||
| 122 | } |
||
| 123 | if (!empty($this->id)) { |
||
| 124 | $buffer[] = '#' . $this->id; |
||
| 125 | } |
||
| 126 | if (!empty($this->attributes)) { |
||
| 127 | foreach ($this->attributes as $attr) { |
||
| 128 | $buffer[] = '['; |
||
| 129 | if (!empty($attr['ns'])) { |
||
| 130 | $buffer[] = $attr['ns'] . '|'; |
||
| 131 | } |
||
| 132 | $buffer[] = $attr['name']; |
||
| 133 | if (!empty($attr['value'])) { |
||
| 134 | $buffer[] = self::attributeOperator($attr['op']); |
||
| 135 | $buffer[] = $attr['value']; |
||
| 136 | } |
||
| 137 | $buffer[] = ']'; |
||
| 138 | } |
||
| 139 | } |
||
| 140 | if (!empty($this->pseudoClasses)) { |
||
| 141 | foreach ($this->pseudoClasses as $ps) { |
||
| 142 | $buffer[] = ':' . $ps['name']; |
||
| 143 | if (isset($ps['value'])) { |
||
| 144 | $buffer[] = '(' . $ps['value'] . ')'; |
||
| 145 | } |
||
| 146 | } |
||
| 147 | } |
||
| 148 | foreach ($this->pseudoElements as $pe) { |
||
| 149 | $buffer[] = '::' . $pe; |
||
| 150 | } |
||
| 151 | |||
| 152 | if (!empty($this->combinator)) { |
||
| 153 | $buffer[] = self::combinatorOperator($this->combinator); |
||
| 154 | } |
||
| 155 | |||
| 156 | } catch (\Exception $e) { |
||
| 157 | return $e->getMessage(); |
||
| 158 | } |
||
| 159 | |||
| 160 | return implode('', $buffer); |
||
| 161 | } |
||
| 164 |
The
breakstatement is not necessary if it is preceded for example by areturnstatement:If you would like to keep this construct to be consistent with other
casestatements, you can safely mark this issue as a false-positive.