| Conditions | 10 |
| Paths | 10 |
| Total Lines | 37 |
| Code Lines | 32 |
| 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 |
||
| 36 | protected function passNodes(array $nodes, Block $block) |
||
| 37 | { |
||
| 38 | foreach ($nodes as $stmt) { |
||
| 39 | switch (get_class($stmt)) { |
||
| 40 | case \PhpParser\Node\Expr\Assign::class: |
||
| 41 | $this->passAssign($stmt, $block); |
||
| 42 | break; |
||
| 43 | case \PhpParser\Node\Stmt\Return_::class: |
||
| 44 | $this->passReturn($stmt, $block); |
||
| 45 | break; |
||
| 46 | case \PhpParser\Node\Stmt\For_::class: |
||
| 47 | $block = $this->passFor($stmt, $block); |
||
| 48 | break; |
||
| 49 | case \PhpParser\Node\Stmt\If_::class: |
||
| 50 | $block = $this->passIf($stmt, $block); |
||
| 51 | break; |
||
| 52 | case \PhpParser\Node\Stmt\While_::class: |
||
| 53 | $block = $this->passWhile($stmt, $block); |
||
| 54 | break; |
||
| 55 | case \PhpParser\Node\Stmt\Throw_::class: |
||
| 56 | $this->passThrow($stmt, $block); |
||
| 57 | break; |
||
| 58 | case \PhpParser\Node\Expr\Exit_::class: |
||
| 59 | $block->addChildren(new Exit_()); |
||
| 60 | break; |
||
| 61 | case \PhpParser\Node\Stmt\Label::class: |
||
| 62 | $block->setExit( |
||
| 63 | $block = new Block($this->lastBlockId++) |
||
| 64 | ); |
||
| 65 | $block->label = $stmt->name; |
||
| 66 | break; |
||
| 67 | default: |
||
| 68 | echo 'Unimplemented ' . get_class($stmt) . PHP_EOL; |
||
| 69 | break; |
||
| 70 | } |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 167 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.