Download the PHP package kytoonlabs/composer-cleanup without Composer
On this page you can find all versions of the php package kytoonlabs/composer-cleanup. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kytoonlabs/composer-cleanup
More information about kytoonlabs/composer-cleanup
Files in kytoonlabs/composer-cleanup
Package composer-cleanup
Short Description A Composer package to review Laravel applications and remove unused dependencies from vendor folder
License Apache-2.0
Informations about the package composer-cleanup
Composer Cleanup
A Composer plugin that analyzes Laravel applications and removes unused dependencies from the vendor folder. This package provides a manual command to keep your vendor directory clean and reduce deployment size.
Features
- Automatic Analysis: Scans your Laravel application files to detect used classes and namespaces
- Smart Detection: Uses PHP Parser to analyze PHP files and extract usage patterns
- Configurable: Customize which directories to scan and which packages to exclude
- Safe Operation: Supports dry-run mode to preview changes before applying them
- Laravel Optimized: Specifically designed for Laravel applications with sensible defaults
- Comprehensive Detection: Identifies classes used in use statements, instantiation, static calls, type hints, and more
Installation
Via Composer (Recommended)
-
Install the package:
-
Create a configuration file:
- Customize the configuration file as needed
Manual Installation
-
Clone this repository:
-
Install dependencies:
- Run the installation script:
Usage
As Composer Script
Run the cleanup command:
Manual Execution
If installed manually, you can run:
This will:
- Analyze your Laravel application for used classes and namespaces
- Identify unused vendor packages
- Remove the unused packages (unless in dry-run mode)
- Regenerate autoload files
Configuration
Create a composer-cleanup.json
file in your project root to customize the behavior:
Configuration Options
- scan_directories: Directories to scan for PHP files (relative to project root)
- exclude_directories: Directories to exclude from scanning
- exclude_packages: Package names to never remove (supports partial matches)
- exclude_package_types: Package types to never remove
- dry_run: If true, shows what would be removed without actually removing
- verbose: If true, shows detailed error messages during parsing
How It Works
- File Scanning: The plugin scans all PHP files in your Laravel application directories
- AST Analysis: Uses PHP Parser to create an Abstract Syntax Tree and extract:
use
statements (imported namespaces)new
expressions (instantiated classes)- Static method calls and property access
- Class constant access
- Type hints in function parameters and return types
- Class inheritance (extends/implements)
- Trait usage
- Instanceof checks
- Catch block exception types
- Package Analysis: Examines each installed package's autoload configuration
- Usage Detection: Determines if a package's classes are actually used in your code
- Cleanup: Removes packages that are not referenced in your application
Safety Features
- Dry Run Mode: Test the cleanup without actually removing files (enabled by default)
- Exclusion Lists: Protect important packages from being removed
- Laravel Framework Protection: Automatically excludes Laravel core packages
- Plugin Protection: Never removes Composer plugins
- Verbose Logging: Detailed output for debugging
- Configuration Validation: Validates JSON configuration files
Example Output
Development
Running Tests
Building
Project Structure
Requirements
- PHP >= 8.2
- Composer >= 2.0
- Laravel application (for intended use)
Dependencies
nikic/php-parser
: For PHP code parsing and AST analysissymfony/finder
: For efficient file system operations
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
This package is open-sourced software licensed under the Apache 2.0 license.
Disclaimer
This tool analyzes static code and may not detect all dynamic usage patterns. Always test your application thoroughly after running the cleanup, especially in production environments. Consider using dry-run mode first to review what would be removed.
Important: The tool runs in dry-run mode by default for safety. Set "dry_run": false
in your configuration to actually remove packages.