forked from JakubOnderka/PHP-Parallel-Lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parallel-lint.php
132 lines (111 loc) · 3.7 KB
/
parallel-lint.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
130
131
132
<?php
use JakubOnderka\PhpParallelLint;
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50303) {
echo "PHP Parallel Lint require PHP 5.3.3 or newer.", PHP_EOL;
die(255);
}
const VERSION = '0.9.2',
SUCCESS = 0,
WITH_ERRORS = 1,
FAILED = 255;
if (in_array('proc_open', explode(',', ini_get('disable_functions')))) {
echo "Function 'proc_open' is required, but it is disabled by disable_functions setting.", PHP_EOL;
die(FAILED);
}
function showOptions()
{
?>
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)
--exclude Exclude a file or directory. If you want exclude multiple items,
use multiple exclude parameters.
-j <num> Run <num> jobs in parallel (default: 10).
--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.
--json Output results as JSON string (require 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.
-h, --help Print this help.
-V, --version Display this application version
<?php
}
function showVersion()
{
echo 'PHP Parallel Lint version ' . VERSION . PHP_EOL;
}
function showUsage()
{
showVersion();
?>
-------------------------------
Usage:
parallel-lint [sa] [-p php] [-e ext] [-j num] [--exclude dir] [files or directories]
<?php
showOptions();
die();
}
if (in_array('-h', $_SERVER['argv']) || in_array('--help', $_SERVER['argv'])) {
showUsage();
}
if (in_array('-V', $_SERVER['argv']) || in_array('--version', $_SERVER['argv'])) {
showVersion();
die();
}
$files = array(
__DIR__ . '/../../autoload.php',
__DIR__ . '/vendor/autoload.php'
);
$autoloadFileFound = false;
foreach ($files as $file) {
if (file_exists($file)) {
require $file;
$autoloadFileFound = true;
break;
}
}
if (!$autoloadFileFound) {
echo 'You need to set up the project dependencies using the following commands:' . PHP_EOL .
'curl -s https://getcomposer.org/installer | php' . PHP_EOL .
'php composer.phar install' . PHP_EOL;
die(FAILED);
}
try {
$settings = PhpParallelLint\Settings::parseArguments($_SERVER['argv']);
if ($settings->json && PHP_VERSION_ID < 50400) {
throw new \Exception('JSON output require PHP version 5.4 and newer.');
}
if ($settings->stdin) {
$settings->addPaths(PhpParallelLint\Settings::getPathsFromStdIn());
}
if (empty($settings->paths)) {
showUsage();
}
$manager = new PhpParallelLint\Manager;
$result = $manager->run($settings);
if ($settings->ignoreFails) {
die($result->hasSyntaxError() ? WITH_ERRORS : SUCCESS);
} else {
die($result->hasError() ? WITH_ERRORS : SUCCESS);
}
} catch (PhpParallelLint\InvalidArgumentException $e) {
echo "Invalid option {$e->getArgument()}", PHP_EOL, PHP_EOL;
showOptions();
die(FAILED);
} catch (PhpParallelLint\Exception $e) {
if (isset($settings) && $settings->json) {
echo json_encode($e);
} else {
echo $e->getMessage(), PHP_EOL;
}
die(FAILED);
} catch (Exception $e) {
echo $e->getMessage(), PHP_EOL;
die(FAILED);
}