-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathunused_scanner
57 lines (48 loc) · 1.76 KB
/
unused_scanner
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env php
<?php
$VERSION = '2.3.0';
/**
* 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 [options] /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';
$optIndex = null;
if ($argc > 1 && strpos($argv[1] ?? '', '-') !== 0) {
$configPath = $argv[1];
$args = array_slice($argv, 1);
$silentMode = in_array('-s', $args, true) || in_array('--silent', $args, true);
$showVersion = in_array('--version', $args, true);
} else {
$options = getopt('s', ['silent', 'version'], $optIndex);
$configPath = (int)$optIndex < $argc && $argc > 1 ? array_slice($argv, $optIndex)[0] : null;
$silentMode = isset($options['s']) || isset($options['silent']);
$showVersion = isset($options['version']);
}
if ($showVersion) {
echo $VERSION . PHP_EOL;
exit(Runner::SUCCESS_CODE);
}
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 (!file_exists($configPath)) {
echo 'Configuration file "' . $configPath . '" not found' . PHP_EOL;
exit(Runner::ARGUMENT_ERROR_CODE);
}
$exitCode = (new Runner((string)$configPath, $silentMode))->run();
exit($exitCode);