forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphpstan
More file actions
executable file
·140 lines (115 loc) · 4.34 KB
/
phpstan
File metadata and controls
executable file
·140 lines (115 loc) · 4.34 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env php
<?php declare(strict_types=1);
use PHPStan\Command\AnalyseCommand;
use PHPStan\Command\BisectCommand;
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 PHPStan\Turbo\TurboExtensionEnabler;
use Symfony\Component\Console\Helper\ProgressBar;
(function () {
error_reporting(E_ALL & ~E_DEPRECATED);
ini_set('display_errors', 'stderr');
gc_disable();
define('__PHPSTAN_RUNNING__', true);
require_once __DIR__ . '/../src/Turbo/TurboExtensionEnabler.php';
TurboExtensionEnabler::enableIfLoaded();
$analysisStartTime = microtime(true);
$devOrPharLoader = require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../preload.php';
$cwd = getcwd();
$composerJsonPath = ComposerHelper::getComposerJsonPath($cwd);
$composer = ComposerHelper::getComposerConfig($cwd);
if ($composer !== null) {
$vendorDirectory = ComposerHelper::getVendorDirFromComposerConfig($cwd, $composer);
} else {
$vendorDirectory = $cwd . '/vendor';
}
$devOrPharLoader->unregister();
// fix missing key for vendor/hoa/protocol/Wrapper.php
$existingComposerAutoloadFiles = $GLOBALS['__composer_autoload_files'] ?? [];
$GLOBALS['__composer_autoload_files'] = array_merge(
$existingComposerAutoloadFiles,
array_fill_keys(['3e76f7f02b41af8cea96018933f6b7e3'], true),
);
$autoloaderInWorkingDirectory = $vendorDirectory . '/autoload.php';
$composerAutoloaderProjectPaths = [];
/** @var array<callable>|false $autoloadFunctionsBefore */
$autoloadFunctionsBefore = spl_autoload_functions();
if (@is_file($autoloaderInWorkingDirectory)) {
if ($composerJsonPath !== null) {
$composerAutoloaderProjectPaths[] = dirname($composerJsonPath);
}
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 BisectCommand());
$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();
})();