Skip to content

Commit cb5b59d

Browse files
PHPStan yourself
1 parent 9fd4ec1 commit cb5b59d

File tree

5 files changed

+33
-13
lines changed

5 files changed

+33
-13
lines changed

composer.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55
"require": {
66
"phpstan/phpstan": "0.11.*"
77
},
8-
"autoload": {
9-
"psr-4": {
10-
"PHPStanMagento1\\": "src/"
11-
}
12-
},
8+
"autoload": {
9+
"psr-4": {
10+
"PHPStanMagento1\\": "src/"
11+
}
12+
},
13+
"scripts": {
14+
"test-quality": [
15+
"phpstan analyse"
16+
],
17+
"test": [
18+
"@test-quality"
19+
]
20+
},
1321
"license": "MIT"
1422
}

phpstan.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
paths:
3+
- src
4+
level: 7

src/Autoload/Magento/ModuleControllerAutoloader.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44

55
use Mage;
66
use ReflectionClass;
7-
8-
function includeFile(string $file)
9-
{
10-
include $file;
11-
}
7+
use Exception;
128

139
class ModuleControllerAutoLoader
1410
{
@@ -23,7 +19,11 @@ public function __construct($codePool, $magentoRoot = null)
2319
{
2420
if (empty($magentRoot)) {
2521
$mageClass = new ReflectionClass(Mage::class);
26-
$magentoRoot = dirname($mageClass->getFileName(), 2);
22+
if ($mageClass->getFileName() !== false) {
23+
$magentoRoot = dirname($mageClass->getFileName(), 2);
24+
} else {
25+
throw new Exception('Could not find path to Mage class');
26+
}
2727
}
2828
$this->codePool = $codePool;
2929
$this->magentoRoot = $magentoRoot;
@@ -39,7 +39,9 @@ public function autoload($className)
3939
if (preg_match('/^([a-zA-Z0-9\x7f-\xff]*)_([a-zA-Z0-9\x7f-\xff]*)_([a-zA-Z0-9_\x7f-\xff]+)/', $className, $match) === 1) {
4040
$controllerFilename = sprintf('%s/app/code/%s/%s/%s/controllers/%s.php', $this->magentoRoot, $this->codePool, $match[1], $match[2], $match[3]);
4141
if (file_exists($controllerFilename)) {
42-
includeFile($controllerFilename);
42+
(function ($file) {
43+
include $file;
44+
})($controllerFilename);
4345
}
4446
}
4547
}

src/Reflection/Varien/Object/MagicMethodReflection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
class MagicMethodReflection implements MethodReflection
1111
{
12+
/**
13+
* @var string
14+
*/
15+
private $name;
16+
1217
/**
1318
* @var ClassReflection
1419
*/

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace PHPStanMagento1\Type\Mage;
3+
namespace PHPStanMagento1\Type\Mage\Core\Model\Layout;
44

55
use PhpParser\Node\Expr\MethodCall;
66
use PhpParser\Node\Scalar\String_;
@@ -11,6 +11,7 @@
1111
use PHPStan\Type\ObjectType;
1212
use PHPStan\Type\Type;
1313

14+
use Mage;
1415
use Mage_Core_Model_Layout;
1516

1617

0 commit comments

Comments
 (0)