Conditions | 19 |
Paths | 1459 |
Total Lines | 124 |
Code Lines | 74 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 380 |
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 |
||
234 | protected function execute(InputInterface $input, OutputInterface $output) |
||
235 | { |
||
236 | $searching_start = microtime(true); |
||
237 | $bugs = $this->getList($this->io->getOption('bugs')); |
||
238 | $revisions = $this->getList($this->io->getOption('revisions')); |
||
239 | |||
240 | if ( $bugs && $revisions ) { |
||
2 ignored issues
–
show
|
|||
241 | throw new \RuntimeException('The "--bugs" and "--revisions" options are mutually exclusive.'); |
||
242 | } |
||
243 | |||
244 | $missing_revisions = array(); |
||
245 | $revisions_by_path = $this->getRevisionsByPath(); |
||
246 | |||
247 | if ( $revisions ) { |
||
1 ignored issue
–
show
|
|||
248 | $revisions = $this->_revisionListParser->expandRanges($revisions); |
||
249 | $revisions_by_path = array_intersect($revisions_by_path, $revisions); |
||
250 | $missing_revisions = array_diff($revisions, $revisions_by_path); |
||
251 | } |
||
252 | elseif ( $bugs ) { |
||
1 ignored issue
–
show
|
|||
253 | // Only show bug-related revisions on given path. The $missing_revisions is always empty. |
||
254 | $revisions_from_bugs = $this->_revisionLog->find('bugs', $bugs); |
||
255 | $revisions_by_path = array_intersect($revisions_by_path, $revisions_from_bugs); |
||
256 | } |
||
257 | |||
258 | $merged_by = $this->getList($this->io->getOption('merged-by')); |
||
259 | |||
260 | if ( $merged_by ) { |
||
1 ignored issue
–
show
|
|||
261 | $merged_by = $this->_revisionListParser->expandRanges($merged_by); |
||
262 | $revisions_by_path = $this->_revisionLog->find('merges', $merged_by); |
||
263 | } |
||
264 | |||
265 | if ( $this->io->getOption('merges') ) { |
||
266 | $revisions_by_path = array_intersect($revisions_by_path, $this->_revisionLog->find('merges', 'all_merges')); |
||
267 | } |
||
268 | elseif ( $this->io->getOption('no-merges') ) { |
||
269 | $revisions_by_path = array_diff($revisions_by_path, $this->_revisionLog->find('merges', 'all_merges')); |
||
270 | } |
||
271 | |||
272 | if ( $this->io->getOption('merged') ) { |
||
273 | $revisions_by_path = array_intersect($revisions_by_path, $this->_revisionLog->find('merges', 'all_merged')); |
||
274 | } |
||
275 | elseif ( $this->io->getOption('not-merged') ) { |
||
276 | $revisions_by_path = array_diff($revisions_by_path, $this->_revisionLog->find('merges', 'all_merged')); |
||
277 | } |
||
278 | |||
279 | $action = $this->io->getOption('action'); |
||
280 | |||
281 | if ( $action ) { |
||
282 | if ( !in_array($action, $this->getAllActions()) ) { |
||
283 | throw new CommandException('The "' . $action . '" action is unknown.'); |
||
284 | } |
||
285 | |||
286 | $revisions_by_path = array_intersect( |
||
287 | $revisions_by_path, |
||
288 | $this->_revisionLog->find('paths', 'action:' . $action) |
||
289 | ); |
||
290 | } |
||
291 | |||
292 | $kind = $this->io->getOption('kind'); |
||
293 | |||
294 | if ( $kind ) { |
||
295 | if ( !in_array($kind, $this->getAllKinds()) ) { |
||
296 | throw new CommandException('The "' . $kind . '" kind is unknown.'); |
||
297 | } |
||
298 | |||
299 | $revisions_by_path = array_intersect( |
||
300 | $revisions_by_path, |
||
301 | $this->_revisionLog->find('paths', 'kind:' . $kind) |
||
302 | ); |
||
303 | } |
||
304 | |||
305 | if ( $missing_revisions ) { |
||
1 ignored issue
–
show
|
|||
306 | throw new CommandException($this->getMissingRevisionsErrorMessage($missing_revisions)); |
||
307 | } |
||
308 | elseif ( !$revisions_by_path ) { |
||
1 ignored issue
–
show
|
|||
309 | throw new CommandException('No matching revisions found.'); |
||
310 | } |
||
311 | |||
312 | rsort($revisions_by_path, SORT_NUMERIC); |
||
313 | |||
314 | if ( $bugs || $revisions ) { |
||
2 ignored issues
–
show
|
|||
315 | // Don't limit revisions, when provided explicitly by user. |
||
316 | $revisions_by_path_with_limit = $revisions_by_path; |
||
317 | } |
||
318 | else { |
||
319 | // Apply limit only, when no explicit bugs/revisions are set. |
||
320 | $revisions_by_path_with_limit = array_slice($revisions_by_path, 0, $this->getMaxCount()); |
||
321 | } |
||
322 | |||
323 | $revisions_by_path_count = count($revisions_by_path); |
||
324 | $revisions_by_path_with_limit_count = count($revisions_by_path_with_limit); |
||
325 | |||
326 | if ( $revisions_by_path_with_limit_count === $revisions_by_path_count ) { |
||
327 | $this->io->writeln(sprintf( |
||
328 | ' * Showing <info>%d</info> revision(-s) in %s:', |
||
329 | $revisions_by_path_with_limit_count, |
||
330 | $this->getRevisionLogIdentifier() |
||
331 | )); |
||
332 | } |
||
333 | else { |
||
334 | $this->io->writeln(sprintf( |
||
335 | ' * Showing <info>%d</info> of <info>%d</info> revision(-s) in %s:', |
||
336 | $revisions_by_path_with_limit_count, |
||
337 | $revisions_by_path_count, |
||
338 | $this->getRevisionLogIdentifier() |
||
339 | )); |
||
340 | } |
||
341 | |||
342 | $searching_duration = microtime(true) - $searching_start; |
||
343 | |||
344 | $printing_start = microtime(true); |
||
345 | $this->printRevisions($revisions_by_path_with_limit); |
||
346 | $printing_duration = microtime(true) - $printing_start; |
||
347 | |||
348 | $debug_info = 'Generation Time: <info>' . round($searching_duration + $printing_duration, 2) . 's</info>'; |
||
349 | $debug_info .= ' ('; |
||
350 | $debug_info .= 'searching: <info>' . round($searching_duration, 2) . 's</info>;'; |
||
351 | $debug_info .= ' printing: <info>' . round($printing_duration, 2) . 's</info>'; |
||
352 | $debug_info .= ').'; |
||
353 | |||
354 | $this->io->writeln( |
||
355 | $debug_info |
||
356 | ); |
||
357 | } |
||
358 | |||
615 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.