-
Notifications
You must be signed in to change notification settings - Fork 21
/
Application.php
129 lines (114 loc) · 4.34 KB
/
Application.php
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
namespace JakubOnderka\PhpParallelLint;
class Application
{
const VERSION = '1.4.0';
// Return codes
const SUCCESS = 0,
WITH_ERRORS = 1,
FAILED = 254; // Error code 255 is reserved for PHP itself
/**
* Run the application
* @return int Return code
*/
public function run()
{
if (in_array('proc_open', explode(',', ini_get('disable_functions')))) {
echo "Function 'proc_open' is required, but it is disabled by the 'disable_functions' ini setting.", PHP_EOL;
return self::FAILED;
}
if (in_array('-h', $_SERVER['argv']) || in_array('--help', $_SERVER['argv'])) {
$this->showUsage();
return self::SUCCESS;
}
if (in_array('-V', $_SERVER['argv']) || in_array('--version', $_SERVER['argv'])) {
$this->showVersion();
return self::SUCCESS;
}
try {
$settings = Settings::parseArguments($_SERVER['argv']);
if ($settings->stdin) {
$settings->addPaths(Settings::getPathsFromStdIn());
}
if (empty($settings->paths)) {
$this->showUsage();
return self::FAILED;
}
$manager = new Manager;
$result = $manager->run($settings);
if ($settings->ignoreFails) {
return $result->hasSyntaxError() ? self::WITH_ERRORS : self::SUCCESS;
} else {
return $result->hasError() ? self::WITH_ERRORS : self::SUCCESS;
}
} catch (InvalidArgumentException $e) {
echo "Invalid option {$e->getArgument()}", PHP_EOL, PHP_EOL;
$this->showOptions();
return self::FAILED;
} catch (Exception $e) {
if (isset($settings) && $settings->format === Settings::FORMAT_JSON) {
echo json_encode($e);
} else {
echo $e->getMessage(), PHP_EOL;
}
return self::FAILED;
} catch (\Exception $e) {
echo $e->getMessage(), PHP_EOL;
return self::FAILED;
}
}
/**
* Outputs the options
*/
private function showOptions()
{
echo <<<HELP
Options:
-p <php> Specify PHP-CGI executable to run (default: 'php').
-s, --short Set short_open_tag to On (default: Off).
-a, --asp Set asp_tags to On (default: Off).
-e <ext> Check only files with selected extensions separated by comma.
(default: php,php3,php4,php5,phtml,phpt)
-j <num> Run <num> jobs in parallel (default: 10).
--exclude Exclude a file or directory. If you want exclude multiple items,
use multiple exclude parameters.
--colors Enable colors in console output.
(disables auto detection of color support)
--no-colors Disable colors in console output.
--no-progress Disable progress in console output.
--checkstyle Output results as Checkstyle XML.
--json Output results as JSON string
(requires PHP 5.4).
--gitlab Output results for the GitLab Code Quality Widget
(requires PHP 5.4).
--blame Try to show git blame for row with error.
--git <git> Path to Git executable to show blame message (default: 'git').
--stdin Load files and folder to test from standard input.
--ignore-fails Ignore failed tests.
--show-deprecated Show deprecations (default: Off).
--syntax-error-callback File with syntax error callback for ability to modify error
-h, --help Print this help.
-V, --version Display the application version
HELP;
}
/**
* Outputs the current version
*/
private function showVersion()
{
echo 'PHP Parallel Lint version ' . self::VERSION.PHP_EOL;
}
/**
* Shows usage
*/
private function showUsage()
{
$this->showVersion();
echo <<<USAGE
-------------------------------
Usage:
parallel-lint [sa] [-p php] [-e ext] [-j num] [--exclude dir] [files or directories]
USAGE;
$this->showOptions();
}
}