| Conditions | 11 |
| Paths | 28 |
| Total Lines | 72 |
| 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 |
||
| 28 | protected function executeConfigured(InputInterface $input, OutputInterface $output, Storeman $storeman): int |
||
| 29 | { |
||
| 30 | $revision = intval($input->getArgument('revision')) ?: $storeman->getLastRevision(); |
||
| 31 | |||
| 32 | if ($revision === null) |
||
| 33 | { |
||
| 34 | $this->consoleStyle->writeln("Could not find any past synchronizations to compare against."); |
||
| 35 | |||
| 36 | return 0; |
||
| 37 | } |
||
| 38 | |||
| 39 | $vaults = $storeman->getVaultContainer(); |
||
| 40 | $vault = $vaults->getPrioritizedVault($vaults->getVaultsHavingRevision($revision)); |
||
| 41 | |||
| 42 | if ($vault === null) |
||
| 43 | { |
||
| 44 | $this->consoleStyle->error("Could not find requested revision {$revision} in any vault."); |
||
| 45 | |||
| 46 | return 1; |
||
| 47 | } |
||
| 48 | |||
| 49 | $index = $vault->getRemoteIndex($revision); |
||
| 50 | |||
| 51 | |||
| 52 | $compareTo = $input->getArgument('compareTo') ? intval($input->getArgument('compareTo')) : null; |
||
| 53 | |||
| 54 | if ($compareTo === 0) |
||
| 55 | { |
||
| 56 | $this->consoleStyle->error("Invalid argument compareTo given."); |
||
| 57 | |||
| 58 | return 1; |
||
| 59 | } |
||
| 60 | elseif ($compareTo === null) |
||
| 61 | { |
||
| 62 | $compareToIndex = $storeman->getLocalIndex(); |
||
| 63 | } |
||
| 64 | else |
||
| 65 | { |
||
| 66 | $vault = $vaults->getPrioritizedVault($vaults->getVaultsHavingRevision($compareTo)); |
||
| 67 | |||
| 68 | if ($vault === null) |
||
| 69 | { |
||
| 70 | $this->consoleStyle->error("Could not find revision {$compareTo} in any vault."); |
||
| 71 | |||
| 72 | return 1; |
||
| 73 | } |
||
| 74 | |||
| 75 | $compareToIndex = $vault->getRemoteIndex($compareTo); |
||
| 76 | |||
| 77 | assert($compareToIndex instanceof Index); |
||
| 78 | } |
||
| 79 | |||
| 80 | |||
| 81 | $mergedIndex = $vault->getIndexMerger()->merge(new PreferLocalConflictHandler(), $index, $compareToIndex, $index); |
||
|
|
|||
| 82 | $diff = $index->getDifference($mergedIndex); |
||
| 83 | |||
| 84 | if ($diff->count() > 0) |
||
| 85 | { |
||
| 86 | $output->writeln(sprintf("Found %d difference(s):\n", $diff->count() ?: 'No')); |
||
| 87 | |||
| 88 | /** @var DisplayIndexComparisonHelper $helper */ |
||
| 89 | $helper = $this->getHelper('displayIndexComparison'); |
||
| 90 | $helper->displayIndexComparison($diff, $output, "r{$revision}", $compareTo ? "r{$compareTo}" : "local"); |
||
| 91 | } |
||
| 92 | |||
| 93 | else |
||
| 94 | { |
||
| 95 | $output->writeln("No differences found."); |
||
| 96 | } |
||
| 97 | |||
| 98 | return 0; |
||
| 99 | } |
||
| 100 | } |
||
| 101 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: