Skip to main content

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 static load() that reads and validates the NEON file (falling back to prune.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 an AnalysisResult.
  • ClassMapBuilder — a node visitor collecting declared class/interface/trait/enum FQCNs with file and line, stored as ClassEntry objects.
  • 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 the Report with the scanned file count.

Blade/

  • BladeViewDiscovery — finds all .blade.php templates under the view paths.
  • BladeReferenceScanner — a node visitor collecting view() / 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 (honoring excludeViews).
  • BladeEntry — value object: view name + file.

Output/

  • Report — holds classOrphans and bladeOrphans; hasOrphans() drives the exit code.
  • ReportFormatter — interface implemented by ConsoleFormatter, JsonFormatter, and HtmlFormatter.

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

DependencyRole
nikic/php-parserPHP source → AST
symfony/consoleCLI framework
symfony/finderFile discovery
nette/neonParsing the prune.neon config