-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphpstan-bootstrap.php
executable file
·52 lines (39 loc) · 1.69 KB
/
phpstan-bootstrap.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
<?php
declare(strict_types=1);
namespace Shopware\Core\DevOps\StaticAnalyze\PHPStan;
use function define;
use function defined;
use function dirname;
use Shopware\Core\DevOps\StaticAnalyze\StaticAnalyzeKernel;
use Shopware\Core\Framework\Plugin\KernelPluginLoader\DbalKernelPluginLoader;
use Symfony\Component\Dotenv\Dotenv;
if (!defined('TEST_PROJECT_DIR')) {
define('TEST_PROJECT_DIR', (function (): string {
if (isset($_SERVER['PROJECT_ROOT']) && file_exists($_SERVER['PROJECT_ROOT'])) {
return $_SERVER['PROJECT_ROOT'];
}
if (isset($_ENV['PROJECT_ROOT']) && file_exists($_ENV['PROJECT_ROOT'])) {
return $_ENV['PROJECT_ROOT'];
}
if (file_exists('vendor') && (file_exists('.env') || file_exists('.env.dist'))) {
return (string) getcwd();
}
$dir = $rootDir = __DIR__;
while (!file_exists($dir . '/.env')) {
if ($dir === dirname($dir)) {
return $rootDir;
}
$dir = dirname($dir);
}
return $dir;
})());
}
$_ENV['PROJECT_ROOT'] = $_SERVER['PROJECT_ROOT'] = TEST_PROJECT_DIR;
$classLoader = require TEST_PROJECT_DIR . '/vendor/autoload.php';
if (class_exists(Dotenv::class) && (file_exists(TEST_PROJECT_DIR . '/.env.local.php') || file_exists(TEST_PROJECT_DIR . '/.env') || file_exists(TEST_PROJECT_DIR . '/.env.dist'))) {
(new Dotenv())->usePutenv()->bootEnv(TEST_PROJECT_DIR . '/.env');
}
$pluginLoader = new DbalKernelPluginLoader($classLoader, null, \Shopware\Core\Kernel::getConnection());
$kernel = new StaticAnalyzeKernel('phpstan_dev', true, $pluginLoader, 'phpstan-test-cache-id');
$kernel->boot();
return $classLoader;