| Conditions | 13 |
| Paths | 5 |
| Total Lines | 46 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 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 . ($block->label ? ' Label: ' . $block->label : '') . 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 | $subVariables = $children->getSubVariables(); |
||
| 65 | if ($subVariables) { |
||
| 66 | foreach ($subVariables as $name => $subVariable) { |
||
| 67 | if ($subVariable) { |
||
| 68 | echo "\t" . $name . ' -> ' . get_class($subVariable) . PHP_EOL; |
||
| 69 | } else { |
||
| 70 | echo "\t" . $name . ' -> NOTHING'; |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | $subBlocks = $children->getSubBlocks(); |
||
| 76 | if ($subBlocks) { |
||
| 77 | foreach ($subBlocks as $name => $subBlock) { |
||
| 78 | if ($subBlock) { |
||
| 79 | echo "\t" . $name . ' -> Block#' . $subBlock->getId() . PHP_EOL; |
||
| 80 | } else { |
||
| 81 | echo "\t" . $name . ' -> NOTHING'; |
||
| 82 | } |
||
| 83 | } |
||
| 84 | } |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | $exit = $block->getExit(); |
||
| 89 | if ($exit) { |
||
| 90 | echo ' -> Block#' . $exit->getId() . PHP_EOL; |
||
| 91 | } |
||
| 92 | |||
| 93 | echo PHP_EOL . PHP_EOL; |
||
| 94 | } |
||
| 95 | } |
||
| 96 | } |
||
| 97 |
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.