定制 renfordt/prune 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

renfordt/prune

Composer 安装命令:

composer require renfordt/prune

包简介

Find orphaned and unused PHP classes in your project

README 文档

README

Badge Packagist Version Packagist PHP Version status-badge Quality Gate Status Coverage

A CLI tool that finds orphaned and unused PHP classes in your project using static AST analysis.

Prune parses your PHP files with nikic/php-parser, collects all class declarations and references, then reports classes that are declared but never referenced anywhere in the scanned codebase. It also supports detecting unused Blade views in Laravel projects.

[!CAUTION] This package is still heavily work in progress and should not be used in production. Use it with caution.

Installation

composer require --dev renfordt/prune

Requires PHP 8.4+.

Usage

Scan one or more directories:

php vendor/bin/prune src
php vendor/bin/prune src app lib

Output formats

By default, results are printed as a console table. You can switch to JSON or HTML:

php vendor/bin/prune src --format=json
php vendor/bin/prune src --format=html

JSON and HTML reports are written to .prune/report.json or .prune/report.html in your project directory. Use --output to override the path:

php vendor/bin/prune src --format=json --output=orphans.json

Blade view analysis

Prune can detect unused Blade views by scanning for @include, @extends, @component, and similar directives, as well as view() calls in PHP code.

Blade analysis is enabled by default. To run Blade analysis only (skipping class detection):

php vendor/bin/prune src --blade

Exit codes

Prune exits with code 1 if any orphans are found, and 0 if the codebase is clean. This makes it suitable for CI pipelines.

Configuration

Create a prune.neon (or prune.neon.dist) file in your project root:

parameters:
    paths:
        - src
        - app
    excludePaths:
        - vendor
        - tests
    extensions:
        - php
    format: console
    blade:
        enabled: true
        viewPaths:
            - resources/views
        excludeViews:
            - errors.404
            - errors.500
OptionDefaultDescription
paths[src]Directories to scan for PHP files
excludePaths[vendor]Paths to exclude from scanning
extensions[php]File extensions to include
formatconsoleOutput format (console, json, html)
blade.enabledtrueEnable Blade view orphan detection
blade.viewPaths[resources/views]Directories containing Blade templates
blade.excludeViews[]Blade view names to ignore (dot notation)

You can also point to a custom config file:

php vendor/bin/prune src --config=custom-prune.neon

How it works

  1. File discovery -- Symfony Finder collects all PHP files in the configured paths
  2. AST parsing -- Each file is parsed into an abstract syntax tree using nikic/php-parser
  3. Class map -- All declared classes, interfaces, traits, and enums are recorded with their fully qualified names
  4. Reference scanning -- All references to classes are collected: extends, implements, new, type hints, static access, instanceof, catch, attributes, and trait use statements
  5. Orphan detection -- Any declared class that appears nowhere in the reference set is reported as an orphan
  6. Blade analysis (optional) -- Blade templates are scanned for view references via directives and PHP view() calls; views with no references are reported

Limitations and risks

Prune performs static analysis only. It does not execute your code, so it cannot detect references that only exist at runtime. Be aware of the following before deleting classes based on its output:

  • Dynamic instantiation -- Classes created via $class = 'App\\MyClass'; new $class(), app()->make(...), or similar patterns are invisible to static analysis. This is common in service containers, factories, and plugin systems.
  • String-based references -- Class names passed as strings (e.g. to configuration arrays, route definitions, or event listeners) are not detected. Laravel service providers, middleware stacks, and config files frequently reference classes this way.
  • Reflection and magic methods -- Code that uses ReflectionClass, class_exists(), or __call/__callStatic to interact with classes dynamically will not be tracked.
  • External consumers -- If your project is a library, its public API classes may appear unused because the consumers live outside the scanned directories.
  • Framework conventions -- Some frameworks auto-discover classes by convention (e.g. Laravel commands, event listeners, policies, or Nova resources). These classes may have no explicit references in your codebase.
  • Blade analysis scope -- Blade view detection only covers @include, @extends, @component, @each, @livewire, and view() calls. Custom directives or JavaScript-driven component rendering are not tracked.
  • Generated code -- Classes generated at build time or by code generators may not exist at scan time, causing their references to be flagged.
  • Scope of analysis -- Only files within the configured paths are scanned. If a class is referenced in a file outside those paths (e.g. in a test suite or a script not under src/), it will still be reported as orphaned.

Recommendation: Treat Prune's output as a starting point for investigation, not as a delete list. Review each reported class before removing it.

License

MIT

renfordt/prune 适用场景与选型建议

renfordt/prune 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 377 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 renfordt/prune 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 renfordt/prune 我们能提供哪些服务?
定制开发 / 二次开发

基于 renfordt/prune 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 377
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 22
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-06