crumbls/laravel-detect-unused-files 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

crumbls/laravel-detect-unused-files

最新稳定版本:0.0.1

Composer 安装命令:

composer require crumbls/laravel-detect-unused-files

包简介

A Laravel package to detect unused files in your project

README 文档

README

This package helps identify unused PHP files in your Laravel application by tracking which files are actually used during application execution.

Why does this exist?

I was asked to help migrate part of a huge app to a smaller app. Copying and pasting created tons of artifacts and unused files. We didn't want to expose anything that isn't critical to this app, so I created this package to find unused app PHP files.

Latest Version on Packagist Total Downloads

⚠️ Development Use Only

Warning: This package is intended for development environments only. It adds additional database queries and file tracking operations that may impact application performance in production.

Requirements

  • PHP 8.3 or higher
  • Laravel 12.0 or higher
  • A Laravel application with a database connection configured

Installation

You can install the package via composer:

composer require crumbls/laravel-detect-unused-files --dev

After installing the package, you need to run the migrations:

php artisan migrate

This will create the necessary file_usage table in your database to track file usage.

How It Works

This package works by:

  1. Tracking all files in your application's app directory
  2. Recording which files are actually loaded during application execution
  3. Allowing you to query for files that have never been loaded (potentially unused)

Usage

Step 1: Add App Files to Tracking

First, add all your application's PHP files to the tracking system:

php artisan files:add-app

This command will scan your app directory for PHP files and add them to the tracking database.

Step 2: Use Your Application

For accurate results, you should use your application normally after running the above command. Browse through different pages and features of your application to ensure that all necessary files are loaded.

The more comprehensive your browsing, the more accurate the results will be. Try to cover:

  • All major features
  • Admin areas
  • Different user roles
  • API endpoints
  • Console commands
  • Scheduled tasks

Step 3: List Unused Files

After using your application, you can check for unused files:

php artisan files:list-unused

This will display a list of PHP files that were never loaded during your application usage.

Additional Options

You can filter the results with various options:

# Limit the number of results
php artisan files:list-unused --limit=10

# Filter by a filename pattern
php artisan files:list-unused --pattern=Controller

# Only show files added more than X days ago
php artisan files:list-unused --days=7

Best Practices

For the most accurate results:

  • Run this in a development environment that mimics your production setup
  • Execute all your application's automated tests to cover edge cases
  • Consider running the tracker over multiple days of normal development use
  • Re-run files:add-app periodically to capture newly added files

How The Package Tracks Files

The package performs the following operations:

  1. Records all PHP files in your app directory
  2. Uses PHP's get_included_files() function to track file usage during request execution
  3. Updates the database on application shutdown to mark loaded files as "used"
  4. Provides commands to query the database for unused files

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

The MIT License (MIT). Please see License File for more information.

Credits

crumbls/laravel-detect-unused-files 适用场景与选型建议

crumbls/laravel-detect-unused-files 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 05 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 crumbls/laravel-detect-unused-files 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-20