| Conditions | 9 |
| Paths | 5 |
| Total Lines | 73 |
| 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 |
||
| 50 | public function printGraph(Block $parent) |
||
| 51 | { |
||
| 52 | $this->visitBlock($parent); |
||
| 53 | |||
| 54 | ksort($this->blocks); |
||
| 55 | |||
| 56 | foreach ($this->blocks as $id => $block) { |
||
| 57 | echo 'Block #' . $id . PHP_EOL; |
||
| 58 | |||
| 59 | $childrens = $block->getChildrens(); |
||
| 60 | if ($childrens) { |
||
| 61 | foreach ($childrens as $children) { |
||
| 62 | echo ' ' . get_class($children) . ($children->willExit() ? ' WILL EXIT!! ' : '') . PHP_EOL; |
||
| 63 | |||
| 64 | if ($children instanceof JumpIf) { |
||
| 65 | $blocks = $children->getSubBlocks(); |
||
| 66 | |||
| 67 | foreach ($blocks as $name => $subBlock) { |
||
| 68 | if ($subBlock) { |
||
| 69 | echo "\t" . $name . ' -> ' . $subBlock->getId() . PHP_EOL; |
||
| 70 | } |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 | |||
| 76 | $exit = $block->getExit(); |
||
| 77 | if ($exit) { |
||
| 78 | echo ' -> ' . $exit->getId() . PHP_EOL; |
||
| 79 | } |
||
| 80 | |||
| 81 | echo PHP_EOL . PHP_EOL; |
||
| 82 | } |
||
| 83 | |||
| 84 | // $childrenSubBlocks = new \SplQueue(); |
||
| 85 | // $childrenSubBlocks->setIteratorMode(\SplQueue::IT_MODE_DELETE); |
||
| 86 | // |
||
| 87 | // |
||
| 88 | // echo 'Block #' . $parent->getId() . PHP_EOL; |
||
| 89 | // |
||
| 90 | // $childrens = $parent->getChildrens(); |
||
| 91 | // if ($childrens) { |
||
| 92 | // foreach ($childrens as $children) { |
||
| 93 | // echo ' ' . get_class($children) . PHP_EOL; |
||
| 94 | // |
||
| 95 | // if ($children instanceof JumpIf) { |
||
| 96 | // $blocks = $children->getSubBlocks(); |
||
| 97 | // |
||
| 98 | // foreach ($blocks as $name => $block) { |
||
| 99 | // if ($block) { |
||
| 100 | // echo "\t" . $name . ' -> ' . $block->getId() . PHP_EOL; |
||
| 101 | // $childrenSubBlocks->push($block); |
||
| 102 | // } |
||
| 103 | // } |
||
| 104 | // } |
||
| 105 | // } |
||
| 106 | // } |
||
| 107 | // |
||
| 108 | // $exit = $parent->getExit(); |
||
| 109 | // if ($exit) { |
||
| 110 | // echo '-> ' . $exit->getId() . PHP_EOL; |
||
| 111 | // } |
||
| 112 | |||
| 113 | // echo PHP_EOL . PHP_EOL; |
||
| 114 | // |
||
| 115 | // if ($exit) { |
||
| 116 | // $this->printBlock($exit); |
||
| 117 | // } |
||
| 118 | // |
||
| 119 | // foreach ($childrenSubBlocks as $block) { |
||
| 120 | // $this->printBlock($block); |
||
| 121 | // } |
||
| 122 | } |
||
| 123 | } |
||
| 125 |
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.