-
Notifications
You must be signed in to change notification settings - Fork 8
/
phpca
executable file
·74 lines (60 loc) · 2.34 KB
/
phpca
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env php
<?php
// ? create-project installation : require installation
$vendor_dir = is_dir(dirname(dirname((__FILE__))).'/vendor') ? dirname(dirname((__FILE__))).'/vendor' : dirname(dirname(dirname(dirname(__FILE__))));
require $vendor_dir.'/autoload.php';
use wapmorgan\PhpCodeAnalyzer\PhpCodeAnalyzer;
$version = file_exists(__DIR__.'/version.txt') ? trim(file_get_contents(__DIR__.'/version.txt')) : PhpCodeAnalyzer::VERSION;
$doc = <<<DOC
PhpCodeAnalyzer $version
Usage:
phpca [-v] [-q] [--output=<path>] [--no-report] [--no-progress] [--since-version=<version>] FILES...
phpca [-v] [-q] [--output=<path>] --extension=<ext> FILES...
phpca -h
phpca --version
Options:
-h --help Show this text
-v --verbose Show more debug text
--version Show version.
-q --quiet Don't print any messages
--output=<path> Path where to generate XML report
--extension=<ext> Look for usage a specific extension
--no-report Turn off summary report
--no-progress Turn off progress
--since-version=<version> Only include extensions not included since version
DOC;
$args = Docopt::handle($doc, ['version' => $version]);
if (isset($args['--verbose']) && $args['--verbose'])
$_ENV['verbose'] = true;
else
$_ENV['verbose'] = false;
if (isset($args['--no-progress']) && $args['--no-progress'])
$_ENV['--no-progress'] = true;
else
$_ENV['--no-progress'] = false;
$_ENV['quiet'] = (isset($args['--quiet']) && $args['--quiet']);
if (isset($args['--output']))
$_ENV['output'] = $args['--output'];
else
$_ENV['output'] = null;
$analyzer = new PhpCodeAnalyzer();
if (isset($args['--since-version']) && $args['--since-version'])
$analyzer->setSinceVersion($args['--since-version']);
if (isset($args['--extension']))
$analyzer->loadOneExtensionData($args['--extension']);
else
$analyzer->loadData();
if (!empty($args['FILES'])) {
$analyzer->printXmlStart();
foreach ($args['FILES'] as $file) {
if (is_dir($file)) {
$analyzer->analyzeDir($file);
} else {
$analyzer->analyzeFile($file);
}
}
if ((!isset($args['--no-report']) || !$args['--no-report']) && !isset($args['--extension'])) {
$analyzer->printUsedExtensions();
}
$analyzer->printXmlEnd();
}