| Conditions | 11 |
| Paths | 28 |
| Total Lines | 84 |
| 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 |
||
| 29 | protected function executeConfigured(InputInterface $input, OutputInterface $output, Storeman $storeman): int |
||
| 30 | { |
||
| 31 | $revision = intval($input->getArgument('revision')) ?: $storeman->getLastRevision(); |
||
| 32 | |||
| 33 | if ($revision === null) |
||
| 34 | { |
||
| 35 | $this->consoleStyle->writeln("Could not find any past synchronizations to compare against."); |
||
| 36 | |||
| 37 | return 0; |
||
| 38 | } |
||
| 39 | |||
| 40 | $vaults = $storeman->getVaultContainer(); |
||
| 41 | $vault = $vaults->getPrioritizedVault($vaults->getVaultsHavingRevision($revision)); |
||
| 42 | |||
| 43 | if ($vault === null) |
||
| 44 | { |
||
| 45 | $this->consoleStyle->error("Could not find requested revision {$revision} in any vault."); |
||
| 46 | |||
| 47 | return 1; |
||
| 48 | } |
||
| 49 | |||
| 50 | $index = $vault->loadRemoteIndex($revision); |
||
| 51 | |||
| 52 | |||
| 53 | $compareTo = intval($input->getArgument('compareTo')) ?: null; |
||
| 54 | |||
| 55 | if ($compareTo === 0) |
||
| 56 | { |
||
| 57 | $this->consoleStyle->error("Invalid argument compareTo given."); |
||
| 58 | |||
| 59 | return 1; |
||
| 60 | } |
||
| 61 | elseif ($compareTo === null) |
||
| 62 | { |
||
| 63 | $compareToIndex = $storeman->getLocalIndex(); |
||
| 64 | } |
||
| 65 | else |
||
| 66 | { |
||
| 67 | $vault = $vaults->getPrioritizedVault($vaults->getVaultsHavingRevision($compareTo)); |
||
| 68 | |||
| 69 | if ($vault === null) |
||
| 70 | { |
||
| 71 | $this->consoleStyle->error("Could not find revision {$compareTo} in any vault."); |
||
| 72 | |||
| 73 | return 1; |
||
| 74 | } |
||
| 75 | |||
| 76 | $compareToIndex = $vault->loadRemoteIndex($compareTo); |
||
| 77 | |||
| 78 | assert($compareToIndex instanceof Index); |
||
| 79 | } |
||
| 80 | |||
| 81 | |||
| 82 | $diff = $index->getDifference($compareToIndex, IndexObject::CMP_IGNORE_BLOBID | IndexObject::CMP_IGNORE_INODE); |
||
| 83 | |||
| 84 | if ($diff->count() > 0) |
||
| 85 | { |
||
| 86 | $output->writeln(sprintf("Found %d difference(s):\n", $diff->count() ?: 'No')); |
||
| 87 | |||
| 88 | $table = new Table($output); |
||
| 89 | $table->setStyle('compact'); |
||
| 90 | $table->setHeaders(['Path', "r{$revision}", $compareTo ? "r{$compareTo}" : "local"]); |
||
| 91 | $table->addRows(array_map(function(IndexObjectComparison $difference) { |
||
| 92 | |||
| 93 | return [ |
||
| 94 | $difference->getRelativePath(), |
||
| 95 | $this->renderIndexObjectColumn($difference->getIndexObjectA()), |
||
| 96 | $this->renderIndexObjectColumn($difference->getIndexObjectB()), |
||
| 97 | ]; |
||
| 98 | |||
| 99 | }, iterator_to_array($diff->getIterator()))); |
||
| 100 | |||
| 101 | $table->render(); |
||
| 102 | |||
| 103 | $output->write("\n"); |
||
| 104 | } |
||
| 105 | |||
| 106 | else |
||
| 107 | { |
||
| 108 | $output->writeln("No differences found."); |
||
| 109 | } |
||
| 110 | |||
| 111 | return 0; |
||
| 112 | } |
||
| 113 | |||
| 124 |