forked from JakubOnderka/PHP-Parallel-Lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparallel-lint.php
executable file
·105 lines (89 loc) · 2.79 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
<?php
use JakubOnderka\PhpParallelLint;
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50303) {
echo "PHP Parallel Lint require PHP 5.3.3 or newer.\n";
die(255);
}
const SUCCESS = 0,
WITH_ERRORS = 1,
FAILED = 255;
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 directory. If you want exclude multiple directory, use
multiple exclude parameters.
-j <num> Run <num> jobs in parallel (default: 10).
--no-colors Disable colors in console output.
--json Output results as JSON string (require PHP 5.4).
--git <git> Path to Git executable to show blame message (default: 'git').
--stdin Load files and folder to test from standard input.
-h, --help Print this help.
<?php
}
function showUsage()
{
?>
PHP Parallel Lint version 0.8
-----------------------------
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();
}
$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 http://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);
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 ($settings->json) {
echo json_encode($e);
} else {
echo $e->getMessage(), PHP_EOL;
}
die(FAILED);
} catch (Exception $e) {
echo $e->getMessage(), PHP_EOL;
die(FAILED);
}