Conditions | 11 |
Paths | 1 |
Total Lines | 55 |
Code Lines | 34 |
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 |
||
131 | public function assemble() |
||
132 | { |
||
133 | $this->callback( |
||
134 | function () { |
||
135 | $stages = $this->get('stages'); |
||
136 | $stageOptions = array(); |
||
137 | // Begin keys from 1 |
||
138 | foreach (array_keys($stages) as $i => $stage) { |
||
139 | $stageOptions[$i + 1] = $stage; |
||
140 | } |
||
141 | |||
142 | $selectedStage = $this->get('stage'); |
||
143 | if ($selectedStage !== null) { |
||
144 | if (!in_array($selectedStage, $stageOptions, true)) { |
||
145 | throw new Exception('Invalid stage'); |
||
146 | } |
||
147 | } else { |
||
148 | if (count($stageOptions) === 1) { |
||
149 | $selectedStage = $stageOptions[1]; |
||
150 | } else { |
||
151 | $selectedStage = $this->choose($this->get('question'), $stageOptions); |
||
152 | } |
||
153 | } |
||
154 | |||
155 | $this->console->output("Selected stage <comment>$selectedStage</comment>", OutputInterface::VERBOSITY_VERBOSE); |
||
156 | |||
157 | $selectedStages = array(); |
||
158 | if ($this->get('sliding')) { |
||
159 | foreach ($stageOptions as $stage) { |
||
160 | $selectedStages[] = $stage; |
||
161 | if ($stage === $selectedStage) { |
||
162 | break; |
||
163 | } |
||
164 | } |
||
165 | } else { |
||
166 | $selectedStages[] = $selectedStage; |
||
167 | } |
||
168 | |||
169 | $message = $this->get('message'); |
||
170 | foreach ($selectedStages as $stage) { |
||
171 | if ($message) { |
||
172 | $this->console->output( |
||
173 | sprintf($message, "<comment>$stage</comment>") |
||
174 | ); |
||
175 | } |
||
176 | $task = clone $this->task; |
||
177 | foreach ($stages[$stage] as $key => $value) { |
||
178 | // Avoid variables overriding parent variables, by prefixing with this |
||
179 | $task->set('this.' . $key, $value); |
||
180 | } |
||
181 | $this->addTask($task); |
||
182 | } |
||
183 | } |
||
184 | ); |
||
185 | } |
||
186 | } |
||
188 |