Skip to content

Commit

Permalink
fix: Cleanup filename diff mode
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Oct 11, 2023
1 parent e5ec207 commit 7c2b127
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 275 deletions.
29 changes: 16 additions & 13 deletions src/Phar/Differ/FilenameDiffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
use Fidry\Console\Input\IO;
use KevinGH\Box\Console\PharInfoRenderer;
use KevinGH\Box\Phar\PharInfo;
use KevinGH\Box\Pharaoh\PharDiff as ParagoniePharDiff;
use SplFileInfo;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Finder\Finder;
use function array_diff;
use function array_map;
use function array_sum;
use function count;
use function explode;
use function iterator_to_array;
use function sprintf;
Expand All @@ -36,18 +36,16 @@ public function diff(
PharInfo $pharInfoB,
IO $io,
): void {
$paragonieDiff = new ParagoniePharDiff($pharInfoA, $pharInfoB);
$paragonieDiff->setVerbose(true);

$pharAFiles = self::collectFiles($pharInfoA);
$pharBFiles = self::collectFiles($pharInfoB);

$diffResult = [
array_diff($pharAFiles, $pharBFiles),
array_diff($pharBFiles, $pharAFiles),
];
$diffCount = array_sum(array_map('count', $diffResult));

if (0 === array_sum(array_map('count', $diffResult))) {
if (0 === $diffCount) {
$io->writeln(Differ::NO_DIFF_MESSAGE);

return;
Expand All @@ -56,15 +54,21 @@ public function diff(
self::printDiff(
$pharInfoA,
$pharInfoB,
$diffResult,
$diffResult[0],
$diffResult[1],
$io,
);
}

/**
* @param list<non-empty-string> $filesInANotInB
* @param list<non-empty-string> $filesInBNotInA
*/
private static function printDiff(
PharInfo $pharInfoA,
PharInfo $pharInfoB,
array $diffResult,
array $filesInANotInB,
array $filesInBNotInA,
IO $io,
): void {
$io->writeln(sprintf(
Expand All @@ -80,15 +84,14 @@ private static function printDiff(

$io->newLine();

self::renderPaths('-', $pharInfoA, $diffResult[0], $io);
self::renderPaths('+', $pharInfoB, $diffResult[1], $io);

$diffCount = array_sum(array_map('count', $diffResult));
self::renderPaths('-', $pharInfoA, $filesInANotInB, $io);
$io->newLine();
self::renderPaths('+', $pharInfoB, $filesInBNotInA, $io);

$io->error(
sprintf(
'%d file(s) difference',
$diffCount,
count($filesInANotInB) + count($filesInBNotInA),
),
);
}
Expand Down Expand Up @@ -119,7 +122,7 @@ private static function renderPaths(string $symbol, PharInfo $pharInfo, array $p
),
);

$io->writeln($lines);
$io->write($lines);
}

/**
Expand Down
261 changes: 0 additions & 261 deletions src/Pharaoh/PharDiff.php

This file was deleted.

1 change: 0 additions & 1 deletion tests/Console/Command/DiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ private static function fileNameDiffPharsProvider(): iterable
+++ Files present in "simple-phar-bar.phar" but not in "simple-phar-foo.phar"
- foo.php [NONE] - 29.00B
+ bar.php [NONE] - 29.00B
[ERROR] 2 file(s) difference
Expand Down

0 comments on commit 7c2b127

Please sign in to comment.