| Conditions | 9 |
| Paths | 18 |
| Total Lines | 57 |
| Code Lines | 39 |
| 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 |
||
| 80 | protected function traverse( |
||
| 81 | TraverseContextInterface $startContext, |
||
| 82 | TraverseFilterInterface $filter, |
||
| 83 | int $traverseMode |
||
| 84 | ): Generator { |
||
| 85 | $lastBranchIndex = $startContext->getBranchContext()->getIndex(); |
||
| 86 | $globalPassedVertexesMap = $startContext->getGlobalPassedVertexesMap(); |
||
| 87 | |||
| 88 | if($traverseMode === self::MODE_WIDE) { |
||
| 89 | $contexts = new Queue([$startContext]); |
||
| 90 | } else { |
||
| 91 | $contexts = new Stack([$startContext]); |
||
| 92 | } |
||
| 93 | while(count($contexts)) { |
||
| 94 | /** @var TraverseContextInterface $currentContext */ |
||
| 95 | $currentContext = $contexts->pop(); |
||
| 96 | $currentVertex = $currentContext->getVertex(); |
||
| 97 | $currentEdge = $currentContext->getEdge(); |
||
| 98 | |||
| 99 | if($filter->getHandleCondition($currentContext)->isSuitableVertex($currentContext->getVertex())) { |
||
| 100 | $cmd = (yield $currentEdge => $currentContext); |
||
| 101 | switch($cmd) { |
||
| 102 | case static::STOP_BRANCH: |
||
| 103 | yield $currentEdge => $currentContext; |
||
| 104 | continue 2; |
||
| 105 | case static::STOP_ALL: |
||
| 106 | return; |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | $passedVertexesMap = $currentContext->getPassedVertexesMap(); |
||
| 111 | $passedVertexesMap[$currentVertex->getId()] = $currentVertex; |
||
| 112 | $globalPassedVertexesMap[$currentVertex->getId()] = $currentVertex; |
||
| 113 | |||
| 114 | $nextVertexes = $this->getNextVertexes($currentVertex, $filter->getPassCondition($currentContext)); |
||
| 115 | $i = 0; |
||
| 116 | foreach($nextVertexes as $edge => $vertex) { |
||
| 117 | $currentBranchContext = $currentContext->getBranchContext(); |
||
| 118 | if(count($nextVertexes) > 1 && $i > 0) { |
||
| 119 | $nextBranchContext = $this->createBranchContext( |
||
| 120 | ++$lastBranchIndex, |
||
| 121 | $currentBranchContext->getIndex(), |
||
| 122 | $currentVertex |
||
| 123 | ); |
||
| 124 | } else { |
||
| 125 | $nextBranchContext = $currentBranchContext; |
||
| 126 | } |
||
| 127 | |||
| 128 | $contexts->push($this->createContext( |
||
| 129 | $vertex, |
||
| 130 | $edge, |
||
| 131 | $nextBranchContext, |
||
| 132 | $passedVertexesMap, |
||
| 133 | $globalPassedVertexesMap |
||
| 134 | )); |
||
| 135 | |||
| 136 | ++$i; |
||
| 137 | } |
||
| 191 |