forked from ateli-development/phpstan-magento1
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new extension-mage-autoload.neon to run stan without static refle…
…ction This extension provides 2 configs: extension-mage-autoload.neon (without static reflection, Mage is autoloaded and executed) extension.neon (Mage.php is not executed thanks to the static reflection) Both modes now run with similar performance, thanks to the config cacheing.
- Loading branch information
Showing
6 changed files
with
110 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# This configuration file doesn't use static reflection for loading Mage class (so it executes code of Mage file). | ||
# Make sure you DON'T have local.xml file in your project when using this config. Otherwise you'll get errors | ||
# about connecting to db | ||
# this config will also throw warnings "PHP Warning: Constant DS already defined in", this is an issue in phpstan | ||
# https://github.com/phpstan/phpstan/issues/6744#event-6194525980 | ||
parametersSchema: | ||
magentoRootPath: string() | ||
parameters: | ||
magentoRootPath: %currentWorkingDirectory%/htdocs | ||
staticReflection: false | ||
excludePaths: | ||
- */app/code/local/*/*/data/* | ||
- */app/code/local/*/*/sql/* | ||
bootstrapFiles: | ||
- %magentoRootPath%/app/Mage.php | ||
- phpstan-bootstrap-mage-autoload.php | ||
|
||
typeAliases: | ||
Mage_Catalog_Model_Entity_Product_Collection: 'Mage_Catalog_Model_Resource_Product_Collection' | ||
callback: 'callable' | ||
earlyTerminatingMethodCalls: | ||
Mage: | ||
- throwException | ||
|
||
services: | ||
- | ||
class: PHPStanMagento1\Reflection\Varien\Object\MagicMethodsReflectionExtension | ||
tags: | ||
- phpstan.broker.methodsClassReflectionExtension | ||
- | ||
class: PHPStanMagento1\Type\Mage\CoreModelLayout\Helper | ||
tags: | ||
- phpstan.broker.dynamicMethodReturnTypeExtension | ||
- | ||
class: PHPStanMagento1\Type\Mage\CoreModelLayout\GetBlockSingleton | ||
tags: | ||
- phpstan.broker.dynamicMethodReturnTypeExtension | ||
- | ||
class: PHPStanMagento1\Type\Mage\GetModel | ||
tags: | ||
- phpstan.broker.dynamicStaticMethodReturnTypeExtension | ||
- | ||
class: PHPStanMagento1\Type\Mage\GetResourceModel | ||
tags: | ||
- phpstan.broker.dynamicStaticMethodReturnTypeExtension | ||
- | ||
class: PHPStanMagento1\Type\Mage\GetSingleton | ||
tags: | ||
- phpstan.broker.dynamicStaticMethodReturnTypeExtension | ||
- | ||
class: PHPStanMagento1\Type\Mage\Helper | ||
tags: | ||
- phpstan.broker.dynamicStaticMethodReturnTypeExtension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
use PHPStanMagento1\Autoload\Magento\ModuleControllerAutoloader; | ||
|
||
/** | ||
* @var $container \PHPStan\DependencyInjection\MemoizingContainer | ||
*/ | ||
$magentoRootPath = $container->getParameter('magentoRootPath'); | ||
if (empty($magentoRootPath)) { | ||
throw new \Exception('Please set "magentoRootPath" in your phpstan.neon.'); | ||
} | ||
|
||
if (!defined('BP')) { | ||
define('BP', $magentoRootPath); | ||
} | ||
|
||
(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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters