PHP Classes

File: unused_scanner

Recommend this page to a friend!
  Classes of Insolita   Unused PHP Composer Packages Scanner   unused_scanner   Download  
File: unused_scanner
Role: Example script
Content type: text/plain
Description: Example script
Class: Unused PHP Composer Packages Scanner
Detect packages in a composer project that unused
Author: By
Last change:
Date: 4 years ago
Size: 1,223 bytes
 

Contents

Class file image Download
#!/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);