-
Notifications
You must be signed in to change notification settings - Fork 574
Expand file tree
/
Copy pathphpstan
More file actions
executable file
·121 lines (99 loc) · 3.73 KB
/
phpstan
File metadata and controls
executable file
·121 lines (99 loc) · 3.73 KB
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
#!/usr/bin/env php
<?php declare(strict_types=1);
use PHPStan\Command\AnalyseCommand;
use PHPStan\Command\ClearResultCacheCommand;
use PHPStan\Command\DiagnoseCommand;
use PHPStan\Command\DumpParametersCommand;
use PHPStan\Command\FixerWorkerCommand;
use PHPStan\Command\WorkerCommand;
use PHPStan\Internal\ComposerHelper;
use Symfony\Component\Console\Helper\ProgressBar;
(function () {
error_reporting(E_ALL & ~E_DEPRECATED);
ini_set('display_errors', 'stderr');
define('__PHPSTAN_RUNNING__', true);
$analysisStartTime = microtime(true);
$devOrPharLoader = require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../preload.php';
$composer = ComposerHelper::getComposerConfig(getcwd());
if ($composer !== null) {
$vendorDirectory = ComposerHelper::getVendorDirFromComposerConfig(getcwd(), $composer);
} else {
$vendorDirectory = getcwd() . '/' . 'vendor';
}
$devOrPharLoader->unregister();
$autoloaderInWorkingDirectory = $vendorDirectory . '/autoload.php';
$composerAutoloaderProjectPaths = [];
/** @var array<callable>|false $autoloadFunctionsBefore */
$autoloadFunctionsBefore = spl_autoload_functions();
if (@is_file($autoloaderInWorkingDirectory)) {
$composerAutoloaderProjectPaths[] = dirname($autoloaderInWorkingDirectory, 2);
require_once $autoloaderInWorkingDirectory;
}
$path = dirname(__DIR__, 3) . '/autoload.php';
if (!extension_loaded('phar')) {
if (@is_file($path)) {
$composerAutoloaderProjectPaths[] = dirname($path, 2);
require_once $path;
}
} else {
$pharPath = \Phar::running(false);
if ($pharPath === '') {
if (@is_file($path)) {
$composerAutoloaderProjectPaths[] = dirname($path, 2);
require_once $path;
}
} else {
$path = dirname($pharPath, 3) . '/autoload.php';
if (@is_file($path)) {
$composerAutoloaderProjectPaths[] = dirname($path, 2);
require_once $path;
}
}
}
/** @var array<callable>|false $autoloadFunctionsAfter */
$autoloadFunctionsAfter = spl_autoload_functions();
if ($autoloadFunctionsBefore !== false && $autoloadFunctionsAfter !== false) {
$newAutoloadFunctions = [];
foreach ($autoloadFunctionsAfter as $after) {
if (
is_array($after)
&& count($after) > 0
) {
if (is_object($after[0])
&& get_class($after[0]) === \Composer\Autoload\ClassLoader::class
) {
continue;
}
if ($after[0] === 'PHPStan\\PharAutoloader') {
continue;
}
}
foreach ($autoloadFunctionsBefore as $before) {
if ($after === $before) {
continue 2;
}
}
$newAutoloadFunctions[] = $after;
}
$GLOBALS['__phpstanAutoloadFunctions'] = $newAutoloadFunctions;
}
$devOrPharLoader->register(true);
$application = new \Symfony\Component\Console\Application(
'PHPStan - PHP Static Analysis Tool',
ComposerHelper::getPhpStanVersion()
);
$application->setDefaultCommand('analyse');
ProgressBar::setFormatDefinition('file_download', ' [%bar%] %percent:3s%% %fileSize%');
$composerAutoloaderProjectPaths = array_map(function(string $s): string {
return str_replace(DIRECTORY_SEPARATOR, '/', $s);
}, $composerAutoloaderProjectPaths);
$reversedComposerAutoloaderProjectPaths = array_values(array_unique(array_reverse($composerAutoloaderProjectPaths)));
$application->add(new AnalyseCommand($reversedComposerAutoloaderProjectPaths, $analysisStartTime));
$application->add(new WorkerCommand($reversedComposerAutoloaderProjectPaths));
$application->add(new ClearResultCacheCommand($reversedComposerAutoloaderProjectPaths));
$application->add(new FixerWorkerCommand($reversedComposerAutoloaderProjectPaths));
$application->add(new DumpParametersCommand($reversedComposerAutoloaderProjectPaths));
$application->add(new DiagnoseCommand($reversedComposerAutoloaderProjectPaths));
$application->run();
})();