| Conditions | 10 |
| Paths | 32 |
| Total Lines | 55 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 102 | public function queueRelations(CC $parentStore, $parentEntity, Node $parentNode, array $parentData): CC |
||
| 103 | { |
||
| 104 | $state = $parentNode->getState(); |
||
| 105 | $sequence = new ContextSequence(); |
||
| 106 | |||
| 107 | // queue all "left" graph branches |
||
| 108 | foreach ($this->dependencies as $name => $relation) { |
||
| 109 | if (!$relation->isCascade() || $parentNode->getState()->visited($name)) { |
||
| 110 | continue; |
||
| 111 | } |
||
| 112 | $state->markVisited($name); |
||
| 113 | |||
| 114 | $command = $this->queueRelation( |
||
| 115 | $parentStore, |
||
| 116 | $parentEntity, |
||
| 117 | $parentNode, |
||
| 118 | $relation, |
||
| 119 | $relation->extract($parentData[$name] ?? null), |
||
| 120 | $parentNode->getRelation($name) |
||
| 121 | ); |
||
| 122 | |||
| 123 | if ($command !== null) { |
||
| 124 | $sequence->addCommand($command); |
||
| 125 | } |
||
| 126 | } |
||
| 127 | |||
| 128 | // queue target entity |
||
| 129 | $sequence->addPrimary($parentStore); |
||
| 130 | |||
| 131 | // queue all "right" graph branches |
||
| 132 | foreach ($this->relations as $name => $relation) { |
||
| 133 | if (!$relation->isCascade() || $parentNode->getState()->visited($name)) { |
||
| 134 | continue; |
||
| 135 | } |
||
| 136 | $state->markVisited($name); |
||
| 137 | |||
| 138 | $command = $this->queueRelation( |
||
| 139 | $parentStore, |
||
| 140 | $parentEntity, |
||
| 141 | $parentNode, |
||
| 142 | $relation, |
||
| 143 | $relation->extract($parentData[$name] ?? null), |
||
| 144 | $parentNode->getRelation($name) |
||
| 145 | ); |
||
| 146 | |||
| 147 | if ($command !== null) { |
||
| 148 | $sequence->addCommand($command); |
||
| 149 | } |
||
| 150 | } |
||
| 151 | |||
| 152 | if (\count($sequence) === 1) { |
||
| 153 | return current($sequence->getCommands()); |
||
| 154 | } |
||
| 155 | |||
| 156 | return $sequence; |
||
| 157 | } |
||
| 208 |