PHPackages                             kytoonlabs/composer-cleanup - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. kytoonlabs/composer-cleanup

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kytoonlabs/composer-cleanup
===========================

A Composer package to review Laravel applications and remove unused dependencies from vendor folder

1.0.0(10mo ago)066Apache-2.0PHPPHP &gt;=8.2

Since Jul 3Pushed 10mo agoCompare

[ Source](https://github.com/kytoonlabs/composer-cleanup)[ Packagist](https://packagist.org/packages/kytoonlabs/composer-cleanup)[ RSS](/packages/kytoonlabs-composer-cleanup/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

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
--------

[](#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
------------

[](#installation)

### Via Composer (Recommended)

[](#via-composer-recommended)

1. Install the package:

```
composer require kytoonlabs/composer-cleanup --dev
```

2. Create a configuration file:

```
cp composer-cleanup.example.json composer-cleanup.json
```

3. Customize the configuration file as needed

### Manual Installation

[](#manual-installation)

1. Clone this repository:

```
git clone https://github.com/kytoonlabs/composer-cleanup.git
cd composer-cleanup
```

2. Install dependencies:

```
composer install
```

3. Run the installation script:

```
chmod +x install.sh
./install.sh
```

Usage
-----

[](#usage)

### As Composer Script

[](#as-composer-script)

Run the cleanup command:

```
composer cleanup
```

### Manual Execution

[](#manual-execution)

If installed manually, you can run:

```
composer cleanup
```

This will:

1. Analyze your Laravel application for used classes and namespaces
2. Identify unused vendor packages
3. Remove the unused packages (unless in dry-run mode)
4. Regenerate autoload files

### Configuration

[](#configuration)

Create a `composer-cleanup.json` file in your project root to customize the behavior:

```
{
  "scan_directories": [
    "app",
    "config",
    "database",
    "resources",
    "routes",
    "tests"
  ],
  "exclude_directories": [
    "vendor",
    "node_modules",
    "storage",
    "bootstrap/cache"
  ],
  "exclude_packages": [
    "laravel/framework",
    "laravel/tinker",
    "laravel/sanctum",
    "laravel/telescope",
    "laravel/horizon",
    "laravel/nova",
    "laravel/fortify",
    "laravel/jetstream",
    "laravel/breeze",
    "laravel/ui"
  ],
  "exclude_package_types": ["composer-plugin", "metapackage", "library"],
  "dry_run": true,
  "verbose": false
}
```

### Configuration Options

[](#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
------------

[](#how-it-works)

1. **File Scanning**: The plugin scans all PHP files in your Laravel application directories
2. **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
3. **Package Analysis**: Examines each installed package's autoload configuration
4. **Usage Detection**: Determines if a package's classes are actually used in your code
5. **Cleanup**: Removes packages that are not referenced in your application

Safety Features
---------------

[](#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
--------------

[](#example-output)

```
Loading configuration from composer-cleanup.json
Analyzing Laravel application for used classes...
Found 3 potentially unused packages:
  - monolog/monolog
  - symfony/console
  - guzzlehttp/guzzle
Removed unused package: monolog/monolog
Removed unused package: symfony/console
Removed unused package: guzzlehttp/guzzle
Vendor cleanup completed successfully!

```

Development
-----------

[](#development)

### Running Tests

[](#running-tests)

```
composer test
```

### Building

[](#building)

```
composer install
```

### Project Structure

[](#project-structure)

```
composer-cleanup/
├── src/                          # Source code
│   ├── Cleaner.php              # Main cleanup logic
│   └── Config.php               # Configuration management
├── tests/                        # Test files
│   └── ComposerCleanerTest.php  # Unit tests
├── composer.json                 # Package configuration
├── composer-cleanup.example.json # Example configuration
├── install.sh                    # Installation script
├── README.md                     # Main documentation
└── LICENSE                       # Apache 2.0 license

```

Requirements
------------

[](#requirements)

- PHP &gt;= 8.2
- Composer &gt;= 2.0
- Laravel application (for intended use)

Dependencies
------------

[](#dependencies)

- `nikic/php-parser`: For PHP code parsing and AST analysis
- `symfony/finder`: For efficient file system operations

Contributing
------------

[](#contributing)

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests
5. Submit a pull request

License
-------

[](#license)

This package is open-sourced software licensed under the [Apache 2.0](LICENSE) license.

Disclaimer
----------

[](#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.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance54

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

319d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d308ca50c5110e5f87b495d95565d10f78588689adab6e653efa1be8c555087e?d=identicon)[kytoonlabs](/maintainers/kytoonlabs)

---

Top Contributors

[![epdl](https://avatars.githubusercontent.com/u/6341099?v=4)](https://github.com/epdl "epdl (22 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kytoonlabs-composer-cleanup/health.svg)

```
[![Health](https://phpackages.com/badges/kytoonlabs-composer-cleanup/health.svg)](https://phpackages.com/packages/kytoonlabs-composer-cleanup)
```

###  Alternatives

[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k111.1M568](/packages/symfony-maker-bundle)[coenjacobs/mozart

Composes all dependencies as a package inside a WordPress plugin

4723.6M20](/packages/coenjacobs-mozart)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[illuminate/session

The Illuminate Session package.

9937.4M753](/packages/illuminate-session)[drupal-code-builder/drupal-code-builder

Code generator for Drupal

27241.1k1](/packages/drupal-code-builder-drupal-code-builder)[yireo/magento2-extensionchecker

Scan the code of a Magento module

96151.6k3](/packages/yireo-magento2-extensionchecker)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
