forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphpstan
executable file
·101 lines (83 loc) · 3.22 KB
/
phpstan
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
#!/usr/bin/env php
<?php declare(strict_types=1);
use PHPStan\Command\AnalyseCommand;
use PHPStan\Command\ClearResultCacheCommand;
use PHPStan\Command\FixerWorkerCommand;
use PHPStan\Command\WorkerCommand;
use Symfony\Component\Console\Helper\ProgressBar;
(function () {
error_reporting(E_ALL);
ini_set('display_errors', 'stderr');
if (version_compare(PHP_VERSION, '7.4.0', '<')) {
// PHP earlier than 7.4.x with OpCache triggers a bug when we intercept
// custom autoloaders' reads to discover file paths. See PHPStan #4881.
ini_set('opcache.enable', 'Off');
}
gc_disable(); // performance boost
define('__PHPSTAN_RUNNING__', true);
$devOrPharLoader = require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../preload.php';
$devOrPharLoader->unregister();
$composerAutoloadFiles = $GLOBALS['__composer_autoload_files'];
if (
!array_key_exists('e88992873b7765f9b5710cab95ba5dd7', $composerAutoloadFiles)
|| !array_key_exists('3e76f7f02b41af8cea96018933f6b7e3', $composerAutoloadFiles)
) {
echo "Composer autoloader changed\n";
exit(1);
}
// empty the global variable so that unprefixed functions from user-space can be loaded
$GLOBALS['__composer_autoload_files'] = [
// fix unprefixed Hoa namespace - files already loaded
'e88992873b7765f9b5710cab95ba5dd7' => true,
'3e76f7f02b41af8cea96018933f6b7e3' => true,
];
$autoloaderInWorkingDirectory = getcwd() . '/vendor/autoload.php';
$composerAutoloaderProjectPaths = [];
if (is_file($autoloaderInWorkingDirectory)) {
$composerAutoloaderProjectPaths[] = dirname($autoloaderInWorkingDirectory, 2);
require_once $autoloaderInWorkingDirectory;
}
$autoloadProjectAutoloaderFile = function (string $file) use (&$composerAutoloaderProjectPaths): void {
$path = dirname(__DIR__) . $file;
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) . $file;
if (is_file($path)) {
$composerAutoloaderProjectPaths[] = dirname($path, 2);
require_once $path;
}
}
}
};
$autoloadProjectAutoloaderFile('/../../autoload.php');
$devOrPharLoader->register(true);
$version = 'Version unknown';
try {
$version = \Jean85\PrettyVersions::getVersion('phpstan/phpstan')->getPrettyVersion();
} catch (\OutOfBoundsException $e) {
}
$application = new \Symfony\Component\Console\Application(
'PHPStan - PHP Static Analysis Tool',
$version
);
$application->setDefaultCommand('analyse');
ProgressBar::setFormatDefinition('file_download', ' [%bar%] %percent:3s%% %fileSize%');
$reversedComposerAutoloaderProjectPaths = array_reverse($composerAutoloaderProjectPaths);
$application->add(new AnalyseCommand($reversedComposerAutoloaderProjectPaths));
$application->add(new WorkerCommand($reversedComposerAutoloaderProjectPaths));
$application->add(new ClearResultCacheCommand($reversedComposerAutoloaderProjectPaths));
$application->add(new FixerWorkerCommand($reversedComposerAutoloaderProjectPaths));
$application->run();
})();