| Conditions | 10 |
| Paths | 10 |
| Total Lines | 79 |
| Code Lines | 46 |
| 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 |
||
| 184 | private function compareContents(InputInterface $input, PharDiff $diff, SymfonyStyle $io): int |
||
| 185 | { |
||
| 186 | $io->comment('<info>Comparing the two archives contents...</info>'); |
||
| 187 | |||
| 188 | if ($input->hasParameterOption(['-c', '--check'])) { |
||
| 189 | return $diff->listChecksums($input->getOption(self::CHECK_OPTION) ?? 'sha384'); |
||
| 190 | } |
||
| 191 | |||
| 192 | if ($input->getOption(self::GNU_DIFF_OPTION)) { |
||
| 193 | $diffResult = $diff->gnuDiff(); |
||
| 194 | } elseif ($input->getOption(self::GIT_DIFF_OPTION)) { |
||
| 195 | $diffResult = $diff->gitDiff(); |
||
| 196 | } else { |
||
| 197 | $diffResult = $diff->listDiff($diff, $io); |
||
| 198 | } |
||
| 199 | |||
| 200 | if (null === $diffResult || [[], []] === $diffResult) { |
||
| 201 | $io->success('The contents are identical'); |
||
| 202 | |||
| 203 | return 0; |
||
| 204 | } |
||
| 205 | |||
| 206 | if (is_string($diffResult)) { |
||
| 207 | // Git or GNU diff: we don't have much control on the format |
||
| 208 | $io->writeln($diffResult); |
||
| 209 | |||
| 210 | return 1; |
||
| 211 | } |
||
| 212 | |||
| 213 | $io->writeln(sprintf( |
||
| 214 | '--- Files present in "%s" but not in "%s"', |
||
| 215 | $diff->getPharA()->getFileName(), |
||
| 216 | $diff->getPharB()->getFileName() |
||
| 217 | )); |
||
| 218 | $io->writeln(sprintf( |
||
| 219 | '+++ Files present in "%s" but not in "%s"', |
||
| 220 | $diff->getPharB()->getFileName(), |
||
| 221 | $diff->getPharA()->getFileName() |
||
| 222 | )); |
||
| 223 | |||
| 224 | $io->newLine(); |
||
| 225 | |||
| 226 | $renderPaths = static function (string $symbol, PharInfo $pharInfo, array $paths, SymfonyStyle $io): void { |
||
| 227 | foreach ($paths as $path) { |
||
| 228 | /** @var PharFileInfo $file */ |
||
| 229 | $file = $pharInfo->getPhar()[str_replace($pharInfo->getRoot(), '', $path)]; |
||
| 230 | |||
| 231 | $compression = '<fg=red>[NONE]</fg=red>'; |
||
| 232 | |||
| 233 | foreach (self::$FILE_ALGORITHMS as $code => $name) { |
||
| 234 | if ($file->isCompressed($code)) { |
||
| 235 | $compression = "<fg=cyan>[$name]</fg=cyan>"; |
||
| 236 | break; |
||
| 237 | } |
||
| 238 | } |
||
| 239 | |||
| 240 | $fileSize = format_size($file->getCompressedSize()); |
||
| 241 | |||
| 242 | $io->writeln( |
||
| 243 | sprintf( |
||
| 244 | '%s %s %s - %s', |
||
| 245 | $symbol, |
||
| 246 | $path, |
||
| 247 | $compression, |
||
| 248 | $fileSize |
||
| 249 | ) |
||
| 250 | ); |
||
| 251 | } |
||
| 252 | }; |
||
| 253 | |||
| 254 | $renderPaths('-', $diff->getPharA()->getPharInfo(), $diffResult[0], $io); |
||
| 255 | $renderPaths('+', $diff->getPharB()->getPharInfo(), $diffResult[1], $io); |
||
| 256 | |||
| 257 | $io->error(sprintf( |
||
| 258 | '%d file(s) difference', |
||
| 259 | count($diffResult[0]) + count($diffResult[1]) |
||
| 260 | )); |
||
| 261 | |||
| 262 | return 1; |
||
| 263 | } |
||
| 280 |