# PruneService

> Reports the orphaned entries of scaffold-lock.json and, when forced, removes them from the lock and deletes the orphaned files that hold only provider content.

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

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

Reports the orphaned entries of `scaffold-lock.json` and, when forced, removes them from the lock and deletes the
orphaned files that hold only provider content.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`run()`](#method-run) | Previews or prunes the orphaned entries of the project lock, ending with a summary line. | `PruneService` |

## Method details

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

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

Previews or prunes the orphaned entries of the project lock, ending with a summary line.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$context` | [`PHPForge\Scaffold\Config\ProjectContext`](/docs/extensions/scaffold/reference/config/projectcontext/index.md) | Project to prune. |
| `$out` | [`PHPForge\Scaffold\Console\OutputWriter`](/docs/extensions/scaffold/reference/console/outputwriter/index.md) | Output sink. |
| `$force` | `bool` | Whether to remove the orphan entries from the lock and delete the unmodified orphan files. |
| `$deleteModified` | `bool` | Whether `$force` also deletes orphan files that hold consumer content. |
| `$exitCode` | `bool` | Whether a preview returns `1` when orphans exist. |

**Returns**

`int`: `1` when a provider manifest cannot be loaded or a file or directory cannot be deleted, or with `$exitCode` when a preview finds orphans; `0` otherwise.

**Throws**

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