# DiffService

> Renders Git-compatible unified diffs of what applying the provider would change in tracked files.

[API reference](/docs/api/index.md) › [Scaffold](/docs/extensions/scaffold/reference/index.md) › [Services](/docs/extensions/scaffold/reference/services/index.md) › DiffService

| final class | `PHPForge\Scaffold\Services\DiffService` |
| --- | --- |
| Source | [`src/Services/DiffService.php`](https://github.com/php-forge/scaffold/blob/main/src/Services/DiffService.php#L18) |

Renders Git-compatible unified diffs of what applying the provider would change in tracked files.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`renderPreview()`](#method-renderPreview) | Writes the header and diff of one preview, `no changes`, or the line-ending notice. | `DiffService` |
| [`run()`](#method-run) | Renders what applying the provider would change in `$file`, or in every tracked, non-ejected file when `$file` is `null`, against the current disk content; orphans are reported, not diffed. | `DiffService` |

## Method details

### renderPreview() <span id="method-renderPreview"></span>

```php
public function renderPreview(PHPForge\Scaffold\Services\ApplyPreview $preview, PHPForge\Scaffold\Console\OutputWriter $out, bool $decorated = false): bool
```

Writes the header and diff of one preview, `no changes`, or the line-ending notice.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$preview` | [`ApplyPreview`](/docs/extensions/scaffold/reference/services/applypreview/index.md) | Preview of the destination to render. |
| `$out` | [`PHPForge\Scaffold\Console\OutputWriter`](/docs/extensions/scaffold/reference/console/outputwriter/index.md) | Output sink. |
| `$decorated` | `bool` | Whether to wrap the diff lines in ANSI color escape codes. |

**Returns**

`bool`: `true` when applying the mapping would create or change the destination, `false` otherwise.

### run() <span id="method-run"></span>

```php
public function run(PHPForge\Scaffold\Config\ProjectContext $context, PHPForge\Scaffold\Console\OutputWriter $out, string|null $file = null, bool $decorated = false, bool $exitCode = false): int
```

Renders what applying the provider would change in `$file`, or in every tracked, non-ejected file when `$file`
is `null`, against the current disk content; orphans are reported, not diffed.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$context` | [`PHPForge\Scaffold\Config\ProjectContext`](/docs/extensions/scaffold/reference/config/projectcontext/index.md) | Project to inspect. |
| `$out` | [`PHPForge\Scaffold\Console\OutputWriter`](/docs/extensions/scaffold/reference/console/outputwriter/index.md) | Output sink. |
| `$file` | `string\|null` | Destination path as recorded in `scaffold-lock.json`, or `null` for every file. |
| `$decorated` | `bool` | Whether to wrap the diff lines in ANSI color escape codes. |
| `$exitCode` | `bool` | Whether to return `1` when applying the provider would change any file. |

**Returns**

`int`: `1` when the file is not tracked, an entry is unsafe, its provider is not allowed, or a file cannot be read, or with `$exitCode` when any file would change; `0` otherwise.

**Throws**

- [`RuntimeException`](https://www.php.net/manual/en/class.runtimeexception.php): when the lock file cannot be read.