Skip to content

Commit 4065ea1

Browse files
committed
some refactorings to reduce code duplication, sql scripts are now excluded via relative path
1 parent 259d1fd commit 4065ea1

15 files changed

+235
-149
lines changed

extension.neon

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ parameters:
22
vendor_path: %currentWorkingDirectory%/vendor
33
bootstrap: %vendor_path%/vianetz/phpstan-magento1/phpstan-bootstrap.php
44
excludes_analyse:
5-
- %currentWorkingDirectory%/htdocs/app/code/local/*/*/data/*
6-
- %currentWorkingDirectory%/htdocs/app/code/local/*/*/sql/*
5+
- */app/code/local/*/*/data/*
6+
- */app/code/local/*/*/sql/*
77
autoload_files:
88
- %currentWorkingDirectory%/htdocs/app/Mage.php
99

@@ -13,10 +13,26 @@ services:
1313
tags:
1414
- phpstan.broker.methodsClassReflectionExtension
1515
-
16-
class: PHPStanMagento1\Type\Mage\Core\Model\Layout\HelperMethodsReturnTypeExtension
16+
class: PHPStanMagento1\Type\Mage\CoreModelLayout\Helper
1717
tags:
1818
- phpstan.broker.dynamicMethodReturnTypeExtension
1919
-
20-
class: PHPStanMagento1\Type\Mage\HelperMethodsReturnTypeExtension
20+
class: PHPStanMagento1\Type\Mage\CoreModelLayout\GetBlockSingleton
21+
tags:
22+
- phpstan.broker.dynamicMethodReturnTypeExtension
23+
-
24+
class: PHPStanMagento1\Type\Mage\GetModel
25+
tags:
26+
- phpstan.broker.dynamicStaticMethodReturnTypeExtension
27+
-
28+
class: PHPStanMagento1\Type\Mage\GetResourceModel
2129
tags:
2230
- phpstan.broker.dynamicStaticMethodReturnTypeExtension
31+
-
32+
class: PHPStanMagento1\Type\Mage\GetSingleton
33+
tags:
34+
- phpstan.broker.dynamicStaticMethodReturnTypeExtension
35+
-
36+
class: PHPStanMagento1\Type\Mage\Helper
37+
tags:
38+
- phpstan.broker.dynamicStaticMethodReturnTypeExtension

phpstan-bootstrap.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,3 @@
1010
// workaround Magento's use of date phpdoc typehint for string type
1111
// better would be to implement the typehint to make it appear string type
1212
class date {}
13-
14-
Mage::app();

src/Autoload/Magento/ModuleControllerAutoloader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function register(): void
3333
spl_autoload_register([$this, 'autoload']);
3434
}
3535

36-
public function autoload($className): void
36+
public function autoload(string $className): void
3737
{
3838
if (preg_match('/^([a-zA-Z0-9\x7f-\xff]*)_([a-zA-Z0-9\x7f-\xff]*)_([a-zA-Z0-9_\x7f-\xff]+)/', $className, $match) === 1) {
3939
$class = str_replace('_', '/', $match[3]);

src/Type/Mage/Core/Model/Layout/HelperMethodsReturnTypeExtension.php

Lines changed: 0 additions & 65 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace PHPStanMagento1\Type\Mage\CoreModelLayout;
5+
6+
final class GetBlockSingleton extends MethodReturnTypeDetector
7+
{
8+
public function getMagentoClassName(string $identifier): string
9+
{
10+
return $this->getMagentoConfig()->getBlockClassName($identifier);
11+
}
12+
13+
protected static function getMethodName(): string
14+
{
15+
return 'getBlockSingleton';
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace PHPStanMagento1\Type\Mage\CoreModelLayout;
5+
6+
final class Helper extends MethodReturnTypeDetector
7+
{
8+
public function getMagentoClassName(string $identifier): string
9+
{
10+
return $this->getMagentoConfig()->getHelperClassName($identifier);
11+
}
12+
13+
protected static function getMethodName(): string
14+
{
15+
return 'helper';
16+
}
17+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace PHPStanMagento1\Type\Mage\CoreModelLayout;
5+
6+
abstract class MethodReturnTypeDetector extends \PHPStanMagento1\Type\Mage\MethodReturnTypeDetector implements \PHPStan\Type\DynamicMethodReturnTypeExtension
7+
{
8+
public function getClass(): string
9+
{
10+
return \Mage_Core_Model_Layout::class;
11+
}
12+
}

src/Type/Mage/GetModel.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace PHPStanMagento1\Type\Mage;
5+
6+
final class GetModel extends StaticMethodReturnTypeDetector
7+
{
8+
public function getMagentoClassName(string $identifier): string
9+
{
10+
return $this->getMagentoConfig()->getModelClassName($identifier);
11+
}
12+
13+
protected static function getMethodName(): string
14+
{
15+
return 'getModel';
16+
}
17+
}

src/Type/Mage/GetResourceModel.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace PHPStanMagento1\Type\Mage;
5+
6+
final class GetResourceModel extends StaticMethodReturnTypeDetector
7+
{
8+
public function getMagentoClassName(string $identifier): string
9+
{
10+
return $this->getMagentoConfig()->getResourceModelClassName($identifier);
11+
}
12+
13+
protected static function getMethodName(): string
14+
{
15+
return 'getResourceModel';
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace PHPStanMagento1\Type\Mage;
5+
6+
final class GetResourceSingleton extends StaticMethodReturnTypeDetector
7+
{
8+
public function getMagentoClassName(string $identifier): string
9+
{
10+
return $this->getMagentoConfig()->getResourceModelClassName($identifier);
11+
}
12+
13+
protected static function getMethodName(): string
14+
{
15+
return 'getResourceSingleton';
16+
}
17+
}

0 commit comments

Comments
 (0)