Conditions | 10 |
Paths | 12 |
Total Lines | 45 |
Code Lines | 23 |
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 |
||
105 | private function visit(CommitOrderNode $vertex) |
||
106 | { |
||
107 | $vertex->state = self::IN_PROGRESS; |
||
108 | |||
109 | foreach ($vertex->dependencyList as $edge) { |
||
110 | $adjacentVertex = $this->nodeList[$edge->to]; |
||
111 | |||
112 | switch ($adjacentVertex->state) { |
||
113 | case self::VISITED: |
||
114 | // Do nothing, since node was already visited |
||
115 | break; |
||
116 | |||
117 | case self::IN_PROGRESS: |
||
118 | if (isset($adjacentVertex->dependencyList[$vertex->hash]) && |
||
119 | $adjacentVertex->dependencyList[$vertex->hash]->weight < $edge->weight) { |
||
120 | // If we have some non-visited dependencies in the in-progress dependency, we |
||
121 | // need to visit them before adding the node. |
||
122 | foreach ($adjacentVertex->dependencyList as $adjacentEdge) { |
||
123 | $adjacentEdgeVertex = $this->nodeList[$adjacentEdge->to]; |
||
124 | |||
125 | if ($adjacentEdgeVertex->state !== self::NOT_VISITED) { |
||
126 | continue; |
||
127 | } |
||
128 | |||
129 | $this->visit($adjacentEdgeVertex); |
||
130 | } |
||
131 | |||
132 | $adjacentVertex->state = self::VISITED; |
||
133 | |||
134 | $this->sortedNodeList[] = $adjacentVertex->value; |
||
135 | } |
||
136 | break; |
||
137 | |||
138 | case self::NOT_VISITED: |
||
139 | $this->visit($adjacentVertex); |
||
140 | } |
||
141 | } |
||
142 | |||
143 | if ($vertex->state === self::VISITED) { |
||
144 | return; |
||
145 | } |
||
146 | |||
147 | $vertex->state = self::VISITED; |
||
148 | |||
149 | $this->sortedNodeList[] = $vertex->value; |
||
150 | } |
||
152 |