# ReapplyService

> Rewrites tracked files from their provider stubs; without force it merges append and prepend files and skips ejected, adopted, user-modified and existing preserve files; it always skips orphaned files.

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

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

Rewrites tracked files from their provider stubs; without `force` it merges `append` and `prepend` files and skips
ejected, adopted, user-modified and existing `preserve` files; it always skips orphaned files.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`run()`](#method-run) | Reapplies the tracked files that match the filters and records their new hashes in `scaffold-lock.json`, or only prints what would change with `$dryRun`, ending with a summary line. | `ReapplyService` |

## Method details

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

```php
public function run(PHPForge\Scaffold\Config\ProjectContext $context, PHPForge\Scaffold\Console\OutputWriter $out, string $file = '', string $provider = '', bool $force = false, bool $dryRun = false, bool $exitCode = false): int
```

Reapplies the tracked files that match the filters and records their new hashes in `scaffold-lock.json`, or only
prints what would change with `$dryRun`, ending with a summary line.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$context` | [`PHPForge\Scaffold\Config\ProjectContext`](/docs/extensions/scaffold/reference/config/projectcontext/index.md) | Project to reapply. |
| `$out` | [`PHPForge\Scaffold\Console\OutputWriter`](/docs/extensions/scaffold/reference/console/outputwriter/index.md) | Output sink. |
| `$file` | `string` | Destination path to reapply, or an empty string for every tracked file. |
| `$provider` | `string` | Provider package name to reapply, or an empty string for every provider. |
| `$force` | `bool` | Whether to overwrite every matching file with its stub, including ejected, adopted, user-modified, `preserve`, `append` and `prepend` files, and to clear the `ejected` and `adopted` flags. |
| `$dryRun` | `bool` | Whether to print the diff of every file that would change instead of writing anything. |
| `$exitCode` | `bool` | Whether a dry run returns `1` when any file would change. |

**Returns**

`int`: `1` when a filter matches no tracked file or an entry was skipped for an error (unsafe entry, provider not allowed, missing stub, unknown mode, read, hash or write failure), or with `$dryRun` and `$exitCode` when any file would change; `0` otherwise, including user-modified, `preserve`, ejected and orphaned skips.

**Throws**

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