Skip to content

Commit 00f0bc6

Browse files
committed
Remove MagentoCore class
1 parent 4d07c88 commit 00f0bc6

File tree

7 files changed

+159
-656
lines changed

7 files changed

+159
-656
lines changed

composer.json

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
{
22
"name": "macopedia/phpstan-magento1",
33
"description": "Extension for PHPStan to allow analysis of Magento 1 code.",
4-
"type": "library",
4+
"type": "phpstan-extension",
5+
"license": "MIT",
56
"require": {
6-
"phpstan/phpstan": "^1.12.11 | ^2.0.2",
77
"php": ">= 7.4"
88
},
9-
"replace": {
10-
"inviqa/phpstan-magento1": "0.1.5",
11-
"vianetz/phpstan-magento1": "0.1.5"
9+
"require-dev": {
10+
"phpstan/phpstan": "^2.0",
11+
"phpstan/phpstan-strict-rules": "^2.0"
1212
},
1313
"autoload": {
1414
"psr-4": {
1515
"PHPStanMagento1\\": "src/"
1616
}
1717
},
18+
"replace": {
19+
"inviqa/phpstan-magento1": "0.1.5",
20+
"vianetz/phpstan-magento1": "0.1.5"
21+
},
1822
"scripts": {
1923
"test-quality": [
2024
"phpstan analyse"
@@ -23,5 +27,11 @@
2327
"@test-quality"
2428
]
2529
},
26-
"license": "MIT"
30+
"extra": {
31+
"phpstan": {
32+
"includes": [
33+
"extension.neon"
34+
]
35+
}
36+
}
2737
}

extension.neon

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
parametersSchema:
22
magentoRootPath: string()
33
enforceMagicMethodDocBlock: bool()
4+
useLocalXml: bool()
45
parameters:
56
magentoRootPath: %currentWorkingDirectory%/htdocs
67
enforceMagicMethodDocBlock: false
7-
excludePaths:
8-
- */app/code/local/*/*/data/*
9-
- */app/code/local/*/*/sql/*
8+
useLocalXml: false
109
bootstrapFiles:
11-
- phpstan-bootstrap.php
12-
scanFiles:
13-
- %magentoRootPath%/app/Mage.php
14-
typeAliases:
15-
Mage_Catalog_Model_Entity_Product_Collection: 'Mage_Catalog_Model_Resource_Product_Collection'
16-
callback: 'callable'
17-
earlyTerminatingMethodCalls:
18-
Mage:
19-
- throwException
10+
- %currentWorkingDirectory%/app/Mage.php
2011

2112
services:
2213
mageCoreConfig:
2314
class: PHPStanMagento1\Config\MageCoreConfig
15+
arguments:
16+
useLocalXml: %useLocalXml%
2417

2518
## Dynamic Return Type Extension to return correct class from Mage::getModel() etc
2619
-

src/Autoload/Magento/ModuleControllerAutoloader.php

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/Config/MageCoreConfig.php

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,26 @@
22

33
namespace PHPStanMagento1\Config;
44

5+
use Mage;
6+
use Mage_Core_Model_Config;
7+
58
final class MageCoreConfig
69
{
7-
/**
8-
* @var MagentoCore|\Mage_Core_Model_Config|null
9-
*/
10-
protected static $config;
10+
private bool $useLocalXml;
11+
private bool $hasInitialized = false;
1112

12-
/**
13-
* Load Magento XML configuration
14-
*
15-
* @return MagentoCore|\Mage_Core_Model_Config
16-
*/
17-
public function getConfig()
13+
public function __construct(bool $useLocalXml)
1814
{
19-
if (self::$config) {
20-
return self::$config;
21-
}
15+
$this->useLocalXml = $useLocalXml;
16+
}
2217

23-
//change this to DI of staticReflection config
24-
if (\defined('staticReflection')) {
25-
$config = new MagentoCore();
26-
$config->loadBase();
27-
$config->loadModules();
28-
} else {
29-
$config = \Mage::app()->getConfig();
18+
public function getConfig(): Mage_Core_Model_Config
19+
{
20+
if ($this->hasInitialized === false && $this->useLocalXml === false) {
21+
$this->hasInitialized = true;
22+
Mage::init('', 'store', ['is_installed' => false]);
3023
}
31-
self::$config = $config;
32-
return self::$config;
24+
return Mage::app()->getConfig();
3325
}
3426

3527
/**
@@ -40,17 +32,26 @@ public function getClassNameConverterFunction(string $class, string $method): ?c
4032
switch ("$class::$method") {
4133
case 'Mage::getModel':
4234
case 'Mage::getSingleton':
35+
case 'Mage_Core_Model_Config::getModelInstance':
4336
return fn (string $alias) => $this->getConfig()->getModelClassName($alias);
4437
case 'Mage::getResourceModel':
4538
case 'Mage::getResourceSingleton':
39+
case 'Mage_Core_Model_Config::getResourceModelInstance':
4640
return fn (string $alias) => $this->getConfig()->getResourceModelClassName($alias);
41+
case 'Mage::getResourceHelper':
42+
case 'Mage_Core_Model_Config::getResourceHelper':
43+
case 'Mage_Core_Model_Config::getResourceHelperInstance':
44+
return fn (string $alias) => $this->getConfig()->getResourceHelperClassName($alias);
4745
case 'Mage_Core_Model_Layout::createBlock':
4846
case 'Mage_Core_Model_Layout::getBlockSingleton':
4947
return fn (string $alias) => $this->getConfig()->getBlockClassName($alias);
5048
case 'Mage::helper':
5149
case 'Mage_Core_Model_Layout::helper':
5250
case 'Mage_Core_Block_Abstract::helper':
51+
case 'Mage_Core_Model_Config::getHelperInstance':
5352
return fn (string $alias) => $this->getConfig()->getHelperClassName($alias);
53+
case 'Mage_Core_Model_Config::getNodeClassInstance':
54+
return fn (string $path) => $this->getConfig()->getNodeClassName($path);
5455
case 'Mage_Admin_Model_User::_helper':
5556
case 'Mage_Adminhtml_Controller_Rss_Abstract::_helper':
5657
case 'Mage_Api_Model_User::_helper':

0 commit comments

Comments
 (0)