Conditions | 7 |
Paths | 64 |
Total Lines | 115 |
Code Lines | 84 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 1 |
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 |
||
143 | protected function updateWorkflowTransitionLogs(LoggerInterface $logger, $dryRun) |
||
144 | { |
||
145 | // Delete old workflow transition logs |
||
146 | $params = [ |
||
147 | 'step_from_id' => $this->getStepIdByName($logger, 'open'), |
||
148 | 'step_to_id' => $this->getStepIdByName($logger, 'won'), |
||
149 | ]; |
||
150 | $types = [ |
||
151 | 'step_from_id' => Type::INTEGER, |
||
152 | 'step_to_id' => Type::INTEGER, |
||
153 | ]; |
||
154 | $sql = 'DELETE FROM oro_workflow_transition_log' . |
||
155 | ' WHERE step_from_id = :step_from_id AND step_to_id = :step_to_id'; |
||
156 | $this->logQuery($logger, $sql, $params, $types); |
||
157 | if (!$dryRun) { |
||
158 | $this->connection->executeUpdate($sql, $params, $types); |
||
159 | } |
||
160 | |||
161 | // Update current step for workflow items from won to open |
||
162 | $params = [ |
||
163 | 'new_current_step_id' => $this->getStepIdByName($logger, 'open'), |
||
164 | 'old_current_step_id' => $this->getStepIdByName($logger, 'won'), |
||
165 | ]; |
||
166 | $types = [ |
||
167 | 'new_current_step_id' => Type::INTEGER, |
||
168 | 'old_current_step_id' => Type::INTEGER, |
||
169 | ]; |
||
170 | $sql = 'UPDATE oro_workflow_item SET current_step_id = :new_current_step_id' . |
||
171 | ' WHERE current_step_id = :old_current_step_id'; |
||
172 | $this->logQuery($logger, $sql, $params, $types); |
||
173 | if (!$dryRun) { |
||
174 | $this->connection->executeUpdate($sql, $params, $types); |
||
175 | } |
||
176 | |||
177 | // Update old requalify transition to reopen |
||
178 | $params = [ |
||
179 | 'new_transition' => 'reopen', |
||
180 | 'old_transitions' => ['requalify_lost', 'requalify_won'], |
||
181 | 'step_to_id' => $this->getStepIdByName($logger, 'open'), |
||
182 | ]; |
||
183 | $types = [ |
||
184 | 'new_transition' => Type::STRING, |
||
185 | 'old_transitions' => Connection::PARAM_STR_ARRAY, |
||
186 | 'step_to_id' => Type::INTEGER, |
||
187 | ]; |
||
188 | $sql = 'UPDATE oro_workflow_transition_log SET transition = :new_transition' . |
||
189 | ' WHERE transition IN (:old_transitions) AND step_to_id = :step_to_id'; |
||
190 | $this->logQuery($logger, $sql, $params, $types); |
||
191 | if (!$dryRun) { |
||
192 | $this->connection->executeUpdate($sql, $params, $types); |
||
193 | } |
||
194 | |||
195 | // Define and specify won step |
||
196 | $params = [ |
||
197 | 'new_transition' => 'close_won', |
||
198 | 'old_transition' => 'close_as_won', |
||
199 | 'new_step_to_id' => $this->getStepIdByName($logger, 'won'), |
||
200 | 'old_step_to_id' => $this->getStepIdByName($logger, 'lost'), |
||
201 | 'step_from_id' => $this->getStepIdByName($logger, 'open') |
||
202 | ]; |
||
203 | $types = [ |
||
204 | 'new_transition' => Type::STRING, |
||
205 | 'old_transition' => Type::STRING, |
||
206 | 'new_step_to_id' => Type::INTEGER, |
||
207 | 'old_step_to_id' => Type::INTEGER, |
||
208 | 'step_from_id' => Type::INTEGER, |
||
209 | ]; |
||
210 | $sql = 'UPDATE oro_workflow_transition_log' . |
||
211 | ' SET transition = :new_transition, step_to_id = :new_step_to_id, step_from_id = :step_from_id' . |
||
212 | ' WHERE step_to_id = :old_step_to_id AND transition = :old_transition'; |
||
213 | $this->logQuery($logger, $sql, $params, $types); |
||
214 | if (!$dryRun) { |
||
215 | $this->connection->executeUpdate($sql, $params, $types); |
||
216 | } |
||
217 | |||
218 | // Update old lost transition |
||
219 | $params = [ |
||
220 | 'new_transition' => 'close_lost', |
||
221 | 'old_transition' => 'close_as_lost', |
||
222 | 'step_to_id' => $this->getStepIdByName($logger, 'lost'), |
||
223 | 'step_from_id' => $this->getStepIdByName($logger, 'open') |
||
224 | ]; |
||
225 | $types = [ |
||
226 | 'new_transition' => Type::STRING, |
||
227 | 'old_transition' => Type::STRING, |
||
228 | 'step_to_id' => Type::INTEGER, |
||
229 | 'step_from_id' => Type::INTEGER, |
||
230 | ]; |
||
231 | $sql = 'UPDATE oro_workflow_transition_log SET transition = :new_transition, step_from_id = :step_from_id' . |
||
232 | ' WHERE step_to_id = :step_to_id AND transition = :old_transition'; |
||
233 | $this->logQuery($logger, $sql, $params, $types); |
||
234 | if (!$dryRun) { |
||
235 | $this->connection->executeUpdate($sql, $params, $types); |
||
236 | } |
||
237 | |||
238 | // Update current steps in won workflows items |
||
239 | $params = [ |
||
240 | 'transition' => 'close_won', |
||
241 | 'current_step_id' => $this->getStepIdByName($logger, 'won'), |
||
242 | ]; |
||
243 | $types = [ |
||
244 | 'transition' => Type::STRING, |
||
245 | 'current_step_id' => Type::INTEGER, |
||
246 | ]; |
||
247 | $sql = 'UPDATE oro_workflow_item SET current_step_id = :current_step_id WHERE id IN(' . |
||
248 | ' SELECT workflow_item_id FROM oro_workflow_transition_log WHERE id IN(' . |
||
249 | ' SELECT MAX(id) FROM oro_workflow_transition_log ' . |
||
250 | ' GROUP BY workflow_item_id' . |
||
251 | ') AND transition = :transition' . |
||
252 | ')'; |
||
253 | $this->logQuery($logger, $sql, $params, $types); |
||
254 | if (!$dryRun) { |
||
255 | $this->connection->executeUpdate($sql, $params, $types); |
||
256 | } |
||
257 | } |
||
258 | |||
336 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.