Architecture
A map of Prune's internals for contributors. For a conceptual walkthrough of the analysis flow, see How It Works.
Entry point
PruneApplication is a single-command Symfony Console application exposed through the bin/prune executable. Its sole command is AnalyzeCommand.
The analysis pipeline
AnalyzeCommand wires options and config together, then delegates to PruneAnalyzer, which performs a single pass per file:
AnalyzeCommand
└── Configuration::load() # Config/
└── PruneAnalyzer::analyze() # Analyzer/
├── Finder # file discovery
├── FileParser # Parser/ — parse each file once
├── NodeTraverser
│ ├── NameResolver # resolve short names → FQCN
│ ├── ClassMapBuilder # collect declarations
│ ├── ReferenceScanner # collect class references
│ └── BladeReferenceScanner
├── OrphanDetector # declared − referenced
└── Blade* (optional) # Blade/
└── ReportFormatter # Output/ — console | json | html
Packages
Config/
Configuration— an immutable value object holding all settings, plus a staticload()that reads and validates the NEON file (falling back toprune.neon.dist, then to defaults).
Parser/
FileParser— wraps nikic/php-parser to turn a file path into an array of AST statements.
Analyzer/
PruneAnalyzer— orchestrates discovery, traversal, and detection; returns anAnalysisResult.ClassMapBuilder— a node visitor collecting declared class/interface/trait/enum FQCNs with file and line, stored asClassEntryobjects.ReferenceScanner— a node visitor collecting every referenced FQCN (see What Gets Detected).OrphanDetector— computes the set difference of declarations minus references.ClassEntry— value object: FQCN + file + line.AnalysisResult— bundles theReportwith the scanned file count.
Blade/
BladeViewDiscovery— finds all.blade.phptemplates under the view paths.BladeReferenceScanner— a node visitor collectingview()/Route::view()references from PHP.BladeDirectiveScanner— regex-scans template content for@include,@extends, component tags, Livewire, etc.BladeOrphanDetector— reports discovered views that have no reference (honoringexcludeViews).BladeEntry— value object: view name + file.
Output/
Report— holdsclassOrphansandbladeOrphans;hasOrphans()drives the exit code.ReportFormatter— interface implemented byConsoleFormatter,JsonFormatter, andHtmlFormatter.
Output destinations
For json/html, AnalyzeCommand writes to .prune/report.<format> in the working directory unless --output overrides it. The command validates the destination (rejecting symlinks and non-regular files, and requiring an existing parent directory) before writing.
Key dependencies
| Dependency | Role |
|---|---|
nikic/php-parser | PHP source → AST |
symfony/console | CLI framework |
symfony/finder | File discovery |
nette/neon | Parsing the prune.neon config |