| Conditions | 8 |
| Paths | 14 |
| Total Lines | 76 |
| 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 |
||
| 53 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 54 | { |
||
| 55 | $output->writeln([ |
||
|
|
|||
| 56 | $this->getApplication()->getLongVersion(), |
||
| 57 | '', |
||
| 58 | ]); |
||
| 59 | |||
| 60 | $parser = new JUnitParser(); |
||
| 61 | |||
| 62 | try { |
||
| 63 | $file1 = $input->getOption('input1'); |
||
| 64 | $array1 = $parser->parseFile($file1); |
||
| 65 | } catch (\Exception $e) { |
||
| 66 | $output->writeln('<bg=red;fg=white> ' . $e->getMessage() . ' </>'); |
||
| 67 | return; |
||
| 68 | } |
||
| 69 | |||
| 70 | try { |
||
| 71 | $file2 = $input->getOption('input2'); |
||
| 72 | $array2 = $parser->parseFile($file2); |
||
| 73 | } catch (\Exception $e) { |
||
| 74 | $output->writeln('<bg=red;fg=white> ' . $e->getMessage() . ' </>'); |
||
| 75 | return; |
||
| 76 | } |
||
| 77 | |||
| 78 | $array = $this->merge($array1, $array2); |
||
| 79 | |||
| 80 | foreach ($array as $key => $value) { |
||
| 81 | if (! isset($value['base'])) { |
||
| 82 | $output->writeln('<bg=green;fg=black>+</> ' . $key); |
||
| 83 | continue; |
||
| 84 | } |
||
| 85 | if (! isset($value['current'])) { |
||
| 86 | $output->writeln('<bg=red;fg=yellow>-</> ' . $key); |
||
| 87 | continue; |
||
| 88 | } |
||
| 89 | |||
| 90 | if ($value['base']['result'] != $value['current']['result']) { |
||
| 91 | $output->writeln(sprintf( |
||
| 92 | '<bg=blue;fg=yellow>o</> %s changed from <fg=cyan>%s</> to <fg=magenta>%s</>', |
||
| 93 | $key, |
||
| 94 | $array1[$key]['result'], |
||
| 95 | $array2[$key]['result'] |
||
| 96 | )); |
||
| 97 | continue; |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | $output->writeln(''); |
||
| 102 | if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { |
||
| 103 | $output->writeln([ |
||
| 104 | sprintf( |
||
| 105 | '<bg=green;fg=black>+</>: This test was added in file %s', |
||
| 106 | $file2 |
||
| 107 | ), |
||
| 108 | sprintf( |
||
| 109 | '<bg=red;fg=yellow>-</>: This test was removed in file %s', |
||
| 110 | $file2 |
||
| 111 | ), |
||
| 112 | sprintf( |
||
| 113 | '<bg=blue;fg=yellow>o</>: The test-result changed between file %s and %s', |
||
| 114 | $file1, |
||
| 115 | $file2 |
||
| 116 | ), |
||
| 117 | '' |
||
| 118 | ]); |
||
| 119 | } |
||
| 120 | $output->writeln(sprintf( |
||
| 121 | '<fg=yellow>Analyzed %s tests in total, %s tests in file %s and %s tests in file %s', |
||
| 122 | count($array), |
||
| 123 | count($array1), |
||
| 124 | basename($file1), |
||
| 125 | count($array2), |
||
| 126 | basename($file2) |
||
| 127 | )); |
||
| 128 | } |
||
| 129 | |||
| 146 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: