PHP Classes

Unused PHP Composer Packages Scanner: Detect packages in a composer project that unused

Recommend this page to a friend!
  Info   View files Example   View files View files (27)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 43 All time: 10,756 This week: 107Up
Version License PHP version Categories
unused-scanner 1.0.0MIT/X Consortium ...7Tools, Console, PHP 7
Description 

Author

This package can be used to detect packages in a composer project that unused.

It reads a configuration script that returns options that determine how Composer based projects are scanned.

The package outputs to the command line console screen the scan progress steps and in the end it shows the list of unused packages that were found.

Innovation Award
PHP Programming Innovation award nominee
October 2019
Number 4


Prize: 1 Year Subscription to NomadPHP Advanced PHP Learning
This package can be used to detect packages in a composer project that unused.

It reads a configuration script that returns options that determine how Composer based projects are scanned.

The package outputs to the command line console screen the scan progress steps and in the end it shows the list of unused packages that were found.

Manuel Lemos
Picture of Insolita
  Performance   Level  
Name: Insolita <contact>
Classes: 20 packages by
Country: Russian Federation Russian Federation
Age: 38
All time rank: 335492 in Russian Federation Russian Federation
Week rank: 312 Up13 in Russian Federation Russian Federation Up
Innovation award
Innovation award
Nominee: 14x

Example

#!/usr/bin/env php
<?php
/**
 * Project scanner for detect unused composer dependencies
 * Usage:
 * - composer global require insolita/unused-scanner
 * - prepare config like in example @see scanner_config.example.php
 * - run 'composer dumpautoload' in project root
 * - unused_scanner /path/to/scanner_config.php
 **/
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
    require
__DIR__ . '/vendor/autoload.php';
} else {
    require
__DIR__ . '/../../autoload.php';
}

use
insolita\Scanner\Lib\Runner;

$defaultConfigPath = getcwd() . DIRECTORY_SEPARATOR . 'scanner_config.php';

$configPath = $argv[1] ?? null;

if (
in_array($configPath, ['--silent', '-s'])) {
   
$configPath = null;
   
$silentMode = true;
}

if (!
$configPath && file_exists($defaultConfigPath)) {
   
$configPath = $defaultConfigPath;
    echo
'Default detected config will be used at ' . $defaultConfigPath . PHP_EOL;
}
if (!
$configPath) {
    echo
'Missing required argument - path to config' . PHP_EOL;
    exit(
Runner::ARGUMENT_ERROR_CODE);
}
if (!isset(
$silentMode)) {
   
$silentMode = isset($argv[2]) && in_array($argv[2], ['--silent', '-s']);
}

$exitCode = (new Runner((string)$configPath, $silentMode))->run();

exit(
$exitCode);



Details

Project scanner for detect unused composer dependencies

Build Status

Versions

Use 1.3.x@dev versions for projects with php 5.6, 7.0

Use 2.x versions for projects with php >= 7.1

ChangeLog

see CHANGELOG.md

Installation

composer global require insolita/unused-scanner

Ensure that your ~/.composer/vendor/bin directory declared in $PATH

echo $PATH

if not - you should add it in ~/.bashrc or ~/.profile

Update

composer global update

Usage

prepare configuration file, see scanner_config.example.php

put it in project root (or other place)

run composer dumpautoload in your project directory

run unused_scanner /path/to/configuration/file/scanner_config.php

since 1.1 you can run it without argument, if scanner_config.php existed in current working directory, it will be used by default

For auto-testing:

Add --silent option for skip progress output and return exit code = 16, when unused packages detected

run unused_scanner /path/to/configuration/file/scanner_config.php --silent

Docker:

run `docker run -v pwd:/app tico/unused-scanner /app/path/to/configuration/file/scanner_config.php`

wait for result..

Demo screenshot


  Files folder image Files  
File Role Description
Files folder imageExceptions (1 file)
Files folder imageLib (5 files)
Files folder imagetests (9 files, 1 directory)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file issue_template.md Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file scanner_config.example.php Aux. Auxiliary script
Accessible without login Image file unused.png Icon Icon image
Accessible without login Plain text file unused_scanner Example Example script

  Files folder image Files  /  Exceptions  
File Role Description
  Plain text file InvalidConfigException.php Class Class source

  Files folder image Files  /  Lib  
File Role Description
  Plain text file ComposerReader.php Class Class source
  Plain text file Config.php Class Class source
  Plain text file DependencyMapper.php Class Class source
  Plain text file Runner.php Class Class source
  Plain text file Scanner.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imagestubs (3 files)
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
  Plain text file ComposerReaderTest.php Class Class source
  Plain text file RunnerTest.php Class Class source
  Plain text file ScannerTest.php Class Class source
  Accessible without login Plain text file scanner_test_config_dev.php Aux. Auxiliary script
  Accessible without login Plain text file scanner_test_config_nodev.php Aux. Auxiliary script
  Accessible without login Plain text file scanner_test_config_reported.php Aux. Auxiliary script
  Accessible without login Plain text file scanner_test_config_reported_custom.php Aux. Auxiliary script
  Accessible without login Plain text file stub_composer.json Data Auxiliary data

  Files folder image Files  /  tests  /  stubs  
File Role Description
  Plain text file dummy.php Class Class source
  Accessible without login Plain text file dummy.yml Data Auxiliary data
  Accessible without login Plain text file foo.twig Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:43
This week:0
All time:10,756
This week:107Up