-
-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathFileDiffFactory.php
More file actions
41 lines (34 loc) · 1.3 KB
/
FileDiffFactory.php
File metadata and controls
41 lines (34 loc) · 1.3 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
declare(strict_types=1);
namespace Rector\ChangesReporting\ValueObjectFactory;
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
use Rector\Console\Formatter\ColorConsoleDiffFormatter;
use Rector\Differ\DefaultDiffer;
use Rector\FileSystem\FilePathHelper;
use Rector\ValueObject\Application\File;
use Rector\ValueObject\Reporting\FileDiff;
final readonly class FileDiffFactory
{
public function __construct(
private DefaultDiffer $defaultDiffer,
private FilePathHelper $filePathHelper,
private ColorConsoleDiffFormatter $colorConsoleDiffFormatter
) {
}
/**
* @param RectorWithLineChange[] $rectorsWithLineChanges
*/
public function createFileDiffWithLineChanges(
bool $shouldShowDiffs,
File $file,
string $oldContent,
string $newContent,
array $rectorsWithLineChanges
): FileDiff {
$relativeFilePath = $this->filePathHelper->relativePath($file->getFilePath());
$diff = $shouldShowDiffs ? $this->defaultDiffer->diff($oldContent, $newContent) : '';
$consoleDiff = $shouldShowDiffs ? $this->colorConsoleDiffFormatter->format($diff) : '';
// always keep the most recent diff
return new FileDiff($relativeFilePath, $diff, $consoleDiff, $rectorsWithLineChanges);
}
}