forked from inviqa/phpstan-magento1
-
Notifications
You must be signed in to change notification settings - Fork 2
/
phpstan-bootstrap.php
44 lines (36 loc) · 1.57 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
<?php
declare(strict_types=1);
use PHPStanMagento1\Autoload\Magento\ModuleControllerAutoloader;
/**
* @var $container \PHPStan\DependencyInjection\MemoizingContainer
*/
$magentoRootDir = $container->getParameter('magentoRootDirectory');
if (empty($magentoRootDir)) {
throw new \Exception('Please set "magentoRootDirectory" in your phpstan.neon.');
}
if (! defined('BP')) {
define('BP', $magentoRootDir);
}
// Note: these warnings can be ignored (this is due to the fact that PHPStan is defining these as well and Magento does not use defined():
// Warning: Constant DS/PS already defined ..
(new ModuleControllerAutoloader('local'))->register();
(new ModuleControllerAutoloader('core'))->register();
(new ModuleControllerAutoloader('community'))->register();
/**
* We replace the original Varien_Autoload autoloader with a custom one in order to prevent errors with invalid classes
* that are used throughout the Magento core code.
* The original autoloader would in this case return false and lead to an error in phpstan because the type alias in extension.neon
* is evaluated afterwards.
*
* @see \Varien_Autoload::autoload()
*/
spl_autoload_register(static function($className) {
spl_autoload_unregister([Varien_Autoload::instance(), 'autoload']);
$classFile = str_replace(' ', DIRECTORY_SEPARATOR, ucwords(str_replace('_', ' ', $className)));
$classFile .= '.php';
foreach (explode(':', get_include_path()) as $path) {
if (\file_exists($path . DIRECTORY_SEPARATOR . $classFile)) {
return include $classFile;
}
}
}, true, true);