Skip to content

FileDiffer

github-actions edited this page Apr 19, 2026 · 1 revision

Renders deterministic summaries and unified diffs for file comparisons.


  • Full name: \FastForward\DevTools\Resource\FileDiffer
  • This class is marked as final and can't be subclassed
  • This class is a Final class

Methods

__construct

Creates a new file differ.

public __construct(\FastForward\DevTools\Filesystem\FilesystemInterface $filesystem, \FastForward\DevTools\Resource\DifferInterface $differ): mixed

Parameters:

Parameter Type Description
$filesystem \FastForward\DevTools\Filesystem\FilesystemInterface the filesystem used to read compared file contents
$differ \FastForward\DevTools\Resource\DifferInterface the differ used to generate unified diffs

diff

Compares a source file against the target file that would be overwritten.

public diff(string $sourcePath, string $targetPath): \FastForward\DevTools\Resource\FileDiff

Parameters:

Parameter Type Description
$sourcePath string the source file path that would replace the target
$targetPath string the existing target file path

Return Value:

the rendered comparison result


diffContents

Compares managed content against the current target contents.

public diffContents(string $sourceLabel, string $targetPath, string $sourceContent, string|null $targetContent, string|null $changedSummary = null): \FastForward\DevTools\Resource\FileDiff

Parameters:

Parameter Type Description
$sourceLabel string the human-readable source label shown in summaries
$targetPath string the target file path
$sourceContent string the generated or source content
$targetContent string|null the current target content, or null when the target does not exist
$changedSummary string|null an optional changed-state summary override

Return Value:

the rendered comparison result


colorize

Colorizes a unified diff for decorated console output.

public colorize(string $diff): string

Parameters:

Parameter Type Description
$diff string the plain unified diff

Return Value:

the colorized diff using Symfony Console tags


formatForConsole

Formats a diff payload for console output.

public formatForConsole(string|null $diff, bool $decorated): string|null

Parameters:

Parameter Type Description
$diff string|null the plain unified diff, if available
$decorated bool whether console decoration is enabled

Return Value:

the diff payload ready for console output


Clone this wiki locally