| Conditions | 11 |
| Paths | 27 |
| Total Lines | 69 |
| Code Lines | 48 |
| 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 |
||
| 82 | protected function traverse( |
||
| 83 | TraverseContextInterface $startContext, |
||
| 84 | TraverseFilterInterface $filter, |
||
| 85 | int $traverseMode |
||
| 86 | ): Generator { |
||
| 87 | $lastBranchIndex = $startContext->getBranchContext()->getIndex(); |
||
| 88 | $globalPassedVertexesMap = $startContext->getGlobalPassedVertexesMap(); |
||
| 89 | $contexts = $this->createContextCollection($traverseMode, $startContext); |
||
| 90 | |||
| 91 | while(count($contexts)) { |
||
| 92 | /** @var TraverseContextInterface $currentContext */ |
||
| 93 | $currentContext = $contexts->pop(); |
||
| 94 | $currentVertex = $currentContext->getVertex(); |
||
| 95 | |||
| 96 | $customPassCondition = null; |
||
| 97 | $nextVertex = null; |
||
| 98 | if($filter->matchesHandleCondition($currentContext)) { |
||
| 99 | $cmd = (yield $currentContext); |
||
| 100 | |||
| 101 | if($cmd instanceof FilterConditionInterface) { |
||
| 102 | $customPassCondition = $cmd; |
||
| 103 | yield $currentContext; |
||
| 104 | } elseif($cmd instanceof VertexInterface) { |
||
| 105 | $nextVertex = $cmd; |
||
| 106 | yield $currentContext; |
||
| 107 | } else { |
||
| 108 | switch($cmd) { |
||
| 109 | case static::STOP_BRANCH: |
||
| 110 | yield $currentContext; |
||
| 111 | continue 2; |
||
| 112 | case static::STOP_ALL: |
||
| 113 | return; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | $passedVertexesMap = $currentContext->getPassedVertexesMap(); |
||
| 119 | $passedVertexesMap[$currentVertex->getId()] = $currentVertex; |
||
| 120 | $globalPassedVertexesMap[$currentVertex->getId()] = $currentVertex; |
||
| 121 | |||
| 122 | if ($nextVertex !== null) { |
||
| 123 | $nextVertexes = new TraverseStepIterator([new TraverseStepItem(null, $nextVertex)]); |
||
| 124 | } else { |
||
| 125 | $customPassCondition = $customPassCondition ?? $filter->getPassCondition($currentContext); |
||
| 126 | $nextVertexes = $this->getNextVertexes($currentVertex, $customPassCondition); |
||
| 127 | } |
||
| 128 | |||
| 129 | $i = 0; |
||
| 130 | foreach($nextVertexes as $edge => $vertex) { |
||
| 131 | $currentBranchContext = $currentContext->getBranchContext(); |
||
| 132 | if(count($nextVertexes) > 1 && $i > 0) { |
||
| 133 | $nextBranchContext = $this->createBranchContext( |
||
| 134 | ++$lastBranchIndex, |
||
| 135 | $currentBranchContext->getIndex(), |
||
| 136 | $currentVertex |
||
| 137 | ); |
||
| 138 | } else { |
||
| 139 | $nextBranchContext = $currentBranchContext; |
||
| 140 | } |
||
| 141 | |||
| 142 | $contexts->push($this->createContext( |
||
| 143 | $vertex, |
||
| 144 | $edge, |
||
| 145 | $nextBranchContext, |
||
| 146 | $passedVertexesMap, |
||
| 147 | $globalPassedVertexesMap |
||
| 148 | )); |
||
| 149 | |||
| 150 | ++$i; |
||
| 151 | } |
||
| 231 |