| Conditions | 10 |
| Paths | 5 |
| Total Lines | 34 |
| 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 |
||
| 52 | public function printGraph(Block $parent) |
||
| 53 | { |
||
| 54 | $this->visitBlock($parent); |
||
| 55 | |||
| 56 | ksort($this->blocks); |
||
| 57 | |||
| 58 | foreach ($this->blocks as $id => $block) { |
||
| 59 | echo 'Block #' . $id . ($block->label ? ' Label: ' . $block->label : '') . PHP_EOL; |
||
| 60 | |||
| 61 | $childrens = $block->getChildrens(); |
||
| 62 | if ($childrens) { |
||
| 63 | foreach ($childrens as $children) { |
||
| 64 | echo ' ' . get_class($children) . ($children->willExit() ? ' WILL EXIT!! ' : '') . PHP_EOL; |
||
| 65 | |||
| 66 | if ($children instanceof JumpIf) { |
||
| 67 | $blocks = $children->getSubBlocks(); |
||
| 68 | |||
| 69 | foreach ($blocks as $name => $subBlock) { |
||
| 70 | if ($subBlock) { |
||
| 71 | echo "\t" . $name . ' -> ' . $subBlock->getId() . PHP_EOL; |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | $exit = $block->getExit(); |
||
| 79 | if ($exit) { |
||
| 80 | echo ' -> ' . $exit->getId() . PHP_EOL; |
||
| 81 | } |
||
| 82 | |||
| 83 | echo PHP_EOL . PHP_EOL; |
||
| 84 | } |
||
| 85 | } |
||
| 86 | } |
||
| 87 |
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.