| Conditions | 9 |
| Paths | 9 |
| Total Lines | 84 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 133 | protected function buildTree() |
||
| 134 | { |
||
| 135 | $nodes = []; |
||
| 136 | |||
| 137 | $i = 0; |
||
| 138 | $text = null; |
||
|
|
|||
| 139 | |||
| 140 | while (($value = array_shift($this->matches)) !== null) |
||
| 141 | { |
||
| 142 | switch ($i++ % 3) |
||
| 143 | { |
||
| 144 | case 0: |
||
| 145 | { |
||
| 146 | # |
||
| 147 | # if the trimed value is not empty we preserve the value, |
||
| 148 | # otherwise we discard it. |
||
| 149 | # |
||
| 150 | |||
| 151 | if (trim($value)) |
||
| 152 | { |
||
| 153 | $nodes[] = $value; |
||
| 154 | } |
||
| 155 | } |
||
| 156 | break; |
||
| 157 | |||
| 158 | case 1: |
||
| 159 | { |
||
| 160 | $closing = ($value == '/'); |
||
| 161 | } |
||
| 162 | break; |
||
| 163 | |||
| 164 | case 2: |
||
| 165 | { |
||
| 166 | if (substr($value, -1, 1) == '/') |
||
| 167 | { |
||
| 168 | # |
||
| 169 | # auto closing |
||
| 170 | # |
||
| 171 | |||
| 172 | $nodes[] = $this->parseMarkup(substr($value, 0, -1)); |
||
| 173 | } |
||
| 174 | else if ($closing) |
||
| 175 | { |
||
| 176 | # |
||
| 177 | # closing markup |
||
| 178 | # |
||
| 179 | |||
| 180 | $open = array_pop($this->opened); |
||
| 181 | |||
| 182 | if ($value != $open) |
||
| 183 | { |
||
| 184 | $this->error($value, $open); |
||
| 185 | } |
||
| 186 | |||
| 187 | return $nodes; |
||
| 188 | } |
||
| 189 | else |
||
| 190 | { |
||
| 191 | # |
||
| 192 | # this is an open markup with possible children |
||
| 193 | # |
||
| 194 | |||
| 195 | $node = $this->parseMarkup($value); |
||
| 196 | |||
| 197 | # |
||
| 198 | # push the markup name into the opened markups |
||
| 199 | # |
||
| 200 | |||
| 201 | $this->opened[] = $node['name']; |
||
| 202 | |||
| 203 | # |
||
| 204 | # create the node and parse its children |
||
| 205 | # |
||
| 206 | |||
| 207 | $node['children'] = $this->buildTree($this->matches); |
||
| 208 | |||
| 209 | $nodes[] = $node; |
||
| 210 | } |
||
| 211 | } |
||
| 212 | } |
||
| 213 | } |
||
| 214 | |||
| 215 | return $nodes; |
||
| 216 | } |
||
| 217 | |||
| 293 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.