Skip to content

Commit

Permalink
Remove MagentoCore class
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbeaty committed Dec 26, 2024
1 parent 4d07c88 commit 00f0bc6
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 656 deletions.
22 changes: 16 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
{
"name": "macopedia/phpstan-magento1",
"description": "Extension for PHPStan to allow analysis of Magento 1 code.",
"type": "library",
"type": "phpstan-extension",
"license": "MIT",
"require": {
"phpstan/phpstan": "^1.12.11 | ^2.0.2",
"php": ">= 7.4"
},
"replace": {
"inviqa/phpstan-magento1": "0.1.5",
"vianetz/phpstan-magento1": "0.1.5"
"require-dev": {
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0"
},
"autoload": {
"psr-4": {
"PHPStanMagento1\\": "src/"
}
},
"replace": {
"inviqa/phpstan-magento1": "0.1.5",
"vianetz/phpstan-magento1": "0.1.5"
},
"scripts": {
"test-quality": [
"phpstan analyse"
Expand All @@ -23,5 +27,11 @@
"@test-quality"
]
},
"license": "MIT"
"extra": {
"phpstan": {
"includes": [
"extension.neon"
]
}
}
}
17 changes: 5 additions & 12 deletions extension.neon
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
parametersSchema:
magentoRootPath: string()
enforceMagicMethodDocBlock: bool()
useLocalXml: bool()
parameters:
magentoRootPath: %currentWorkingDirectory%/htdocs
enforceMagicMethodDocBlock: false
excludePaths:
- */app/code/local/*/*/data/*
- */app/code/local/*/*/sql/*
useLocalXml: false
bootstrapFiles:
- phpstan-bootstrap.php
scanFiles:
- %magentoRootPath%/app/Mage.php
typeAliases:
Mage_Catalog_Model_Entity_Product_Collection: 'Mage_Catalog_Model_Resource_Product_Collection'
callback: 'callable'
earlyTerminatingMethodCalls:
Mage:
- throwException
- %currentWorkingDirectory%/app/Mage.php

services:
mageCoreConfig:
class: PHPStanMagento1\Config\MageCoreConfig
arguments:
useLocalXml: %useLocalXml%

## Dynamic Return Type Extension to return correct class from Mage::getModel() etc
-
Expand Down
44 changes: 0 additions & 44 deletions src/Autoload/Magento/ModuleControllerAutoloader.php

This file was deleted.

45 changes: 23 additions & 22 deletions src/Config/MageCoreConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,26 @@

namespace PHPStanMagento1\Config;

use Mage;
use Mage_Core_Model_Config;

final class MageCoreConfig
{
/**
* @var MagentoCore|\Mage_Core_Model_Config|null
*/
protected static $config;
private bool $useLocalXml;
private bool $hasInitialized = false;

/**
* Load Magento XML configuration
*
* @return MagentoCore|\Mage_Core_Model_Config
*/
public function getConfig()
public function __construct(bool $useLocalXml)
{
if (self::$config) {
return self::$config;
}
$this->useLocalXml = $useLocalXml;
}

//change this to DI of staticReflection config
if (\defined('staticReflection')) {
$config = new MagentoCore();
$config->loadBase();
$config->loadModules();
} else {
$config = \Mage::app()->getConfig();
public function getConfig(): Mage_Core_Model_Config
{
if ($this->hasInitialized === false && $this->useLocalXml === false) {
$this->hasInitialized = true;
Mage::init('', 'store', ['is_installed' => false]);
}
self::$config = $config;
return self::$config;
return Mage::app()->getConfig();
}

/**
Expand All @@ -40,17 +32,26 @@ public function getClassNameConverterFunction(string $class, string $method): ?c
switch ("$class::$method") {
case 'Mage::getModel':
case 'Mage::getSingleton':
case 'Mage_Core_Model_Config::getModelInstance':
return fn (string $alias) => $this->getConfig()->getModelClassName($alias);
case 'Mage::getResourceModel':
case 'Mage::getResourceSingleton':
case 'Mage_Core_Model_Config::getResourceModelInstance':
return fn (string $alias) => $this->getConfig()->getResourceModelClassName($alias);
case 'Mage::getResourceHelper':
case 'Mage_Core_Model_Config::getResourceHelper':
case 'Mage_Core_Model_Config::getResourceHelperInstance':
return fn (string $alias) => $this->getConfig()->getResourceHelperClassName($alias);
case 'Mage_Core_Model_Layout::createBlock':
case 'Mage_Core_Model_Layout::getBlockSingleton':
return fn (string $alias) => $this->getConfig()->getBlockClassName($alias);
case 'Mage::helper':
case 'Mage_Core_Model_Layout::helper':
case 'Mage_Core_Block_Abstract::helper':
case 'Mage_Core_Model_Config::getHelperInstance':
return fn (string $alias) => $this->getConfig()->getHelperClassName($alias);
case 'Mage_Core_Model_Config::getNodeClassInstance':
return fn (string $path) => $this->getConfig()->getNodeClassName($path);
case 'Mage_Admin_Model_User::_helper':
case 'Mage_Adminhtml_Controller_Rss_Abstract::_helper':
case 'Mage_Api_Model_User::_helper':
Expand Down
Loading

0 comments on commit 00f0bc6

Please sign in to comment.