Skip to main content

How It Works

Prune answers one question: which declared classes are never referenced? It does this with a single static pass over your code — it never executes anything.

The pipeline

config → discover files → parse (AST) → collect declarations
→ collect references
→ declarations − references = orphans
→ format report

1. Configuration

Prune loads prune.neon / prune.neon.dist (or a --config file) and merges it with command-line arguments. The result determines the paths, exclusions, extensions, output format, and Blade settings for the run. See Configuration File.

2. File discovery

Using Symfony Finder, Prune collects every file in the configured paths whose extension matches extensions and whose path is not in excludePaths.

3. AST parsing

Each file is parsed exactly once into an abstract syntax tree by nikic/php-parser. The tree is then walked by a single traverser carrying several visitors, with a NameResolver prepended so that short names are resolved to fully qualified class names (FQCNs).

4. Building the class map

The ClassMapBuilder visitor records every declared class, interface, trait, and enum — storing each FQCN together with the file and line where it is declared.

5. Scanning references

The ReferenceScanner visitor collects every place a class is used. It recognizes a broad set of reference kinds — see What Gets Detected for the full list, which includes extends/implements, new, static access, type hints, attributes, docblocks, route strings, and selected function calls such as class_exists().

6. Detecting orphans

The OrphanDetector performs a set difference:

orphans = declared classes − referenced classes

Any declared FQCN that never appears in the reference set is reported as an orphan, along with its file and line.

7. Blade analysis (optional)

When enabled, Prune separately discovers all Blade templates, collects view references from PHP view()/Route::view() calls and Blade directives, and reports views that are never referenced. See Blade Analysis.

8. Formatting the report

Finally the report — class orphans plus Blade orphans — is rendered by the selected formatter (console, json, or html) and either printed or written to disk. See Output Formats.

Why a single pass

All visitors share one traversal of each file's AST, so a file is read and parsed only once even though several kinds of information are extracted from it. This keeps analysis fast on large codebases.

Next