-
-
Notifications
You must be signed in to change notification settings - Fork 440
Expand file tree
/
Copy pathConsoleDiffer.php
More file actions
28 lines (22 loc) · 917 Bytes
/
ConsoleDiffer.php
File metadata and controls
28 lines (22 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
declare(strict_types=1);
namespace Rector\Console\Formatter;
use SebastianBergmann\Diff\Differ;
use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
final readonly class ConsoleDiffer
{
private Differ $differ;
public function __construct(
private ColorConsoleDiffFormatter $colorConsoleDiffFormatter
) {
// @see https://github.com/sebastianbergmann/diff#strictunifieddiffoutputbuilder
// @see https://github.com/sebastianbergmann/diff/compare/4.0.4...5.0.0#diff-251edf56a6344c03fa264a4926b06c2cee43c25f66192d5f39ebee912b7442dc for upgrade
$unifiedDiffOutputBuilder = new UnifiedDiffOutputBuilder();
$this->differ = new Differ($unifiedDiffOutputBuilder);
}
public function diff(string $old, string $new): string
{
$diff = $this->differ->diff($old, $new);
return $this->colorConsoleDiffFormatter->format($diff);
}
}