| Conditions | 13 |
| Paths | 9 |
| Total Lines | 26 |
| Code Lines | 18 |
| 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 |
||
| 29 | public function atPosition($line = null, $column = null) |
||
| 30 | { |
||
| 31 | switch (true) { |
||
| 32 | case null === $line && null === $column: |
||
| 33 | return $this->getNodes(); |
||
| 34 | case null !== $line && null === $column: |
||
| 35 | return array_key_exists($line, $this->nodes) |
||
| 36 | ? $this->nodes[$line] |
||
| 37 | : [] |
||
| 38 | ; |
||
| 39 | case null === $line && null !== $column: |
||
| 40 | $nodes = []; |
||
| 41 | foreach ($this->nodes as $i => $nodes) { |
||
| 42 | if (array_key_exists($column, $nodes)) { |
||
| 43 | $nodes[$i] = $nodes[$column]; |
||
| 44 | } |
||
| 45 | } |
||
| 46 | return $nodes; |
||
| 47 | case null !== $line && null !== $column: |
||
| 48 | $nodes = $this->atPosition($line); |
||
| 49 | return array_key_exists($column, $nodes) |
||
| 50 | ? $nodes[$column] |
||
| 51 | : null |
||
| 52 | ; |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 66 |