Skip to content

Commit 259d1fd

Browse files
committed
some housekeeping
1 parent 2e592f6 commit 259d1fd

File tree

7 files changed

+46
-38
lines changed

7 files changed

+46
-38
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"description": "Extension for PHPStan to allow analysis of Magento 1 code.",
44
"type": "library",
55
"require": {
6-
"phpstan/phpstan": "0.11.*",
7-
"php": ">= 7.0",
6+
"phpstan/phpstan": "^0.11",
7+
"php": ">= 7.2",
88
"nikic/php-parser": "^4.4"
99
},
1010
"replace": {

phpstan-bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23

34
use PHPStanMagento1\Autoload\Magento\ModuleControllerAutoloader;
45

src/Autoload/Magento/ModuleControllerAutoloader.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,41 @@
55

66
use Mage;
77
use ReflectionClass;
8-
use Exception;
98

10-
class ModuleControllerAutoloader
9+
final class ModuleControllerAutoloader
1110
{
12-
/**
13-
* @var string
14-
*/
11+
/** @var string */
1512
private $magentoRoot;
1613

14+
/** @var string */
1715
private $codePool;
1816

19-
public function __construct($codePool, $magentoRoot = null)
17+
public function __construct(string $codePool, $magentoRoot = null)
2018
{
2119
if (empty($magentoRoot)) {
2220
$mageClass = new ReflectionClass(Mage::class);
2321
if ($mageClass->getFileName() !== false) {
24-
$magentoRoot = dirname($mageClass->getFileName(), 2);
22+
$magentoRoot = \dirname($mageClass->getFileName(), 2);
2523
} else {
26-
throw new Exception('Could not find path to Mage class');
24+
throw new \RuntimeException('Could not find path to Mage class');
2725
}
2826
}
2927
$this->codePool = $codePool;
3028
$this->magentoRoot = $magentoRoot;
3129
}
3230

33-
public function register()
31+
public function register(): void
3432
{
3533
spl_autoload_register([$this, 'autoload']);
3634
}
3735

38-
public function autoload($className)
36+
public function autoload($className): void
3937
{
4038
if (preg_match('/^([a-zA-Z0-9\x7f-\xff]*)_([a-zA-Z0-9\x7f-\xff]*)_([a-zA-Z0-9_\x7f-\xff]+)/', $className, $match) === 1) {
4139
$class = str_replace('_', '/', $match[3]);
4240
$controllerFilename = sprintf('%s/app/code/%s/%s/%s/controllers/%s.php', $this->magentoRoot, $this->codePool, $match[1], $match[2], $class);
4341
if (file_exists($controllerFilename)) {
44-
(function ($file) {
42+
(static function ($file) {
4543
include $file;
4644
})($controllerFilename);
4745
}

src/Reflection/Varien/Object/MagicMethodReflection.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@
88
use PHPStan\Reflection\MethodReflection;
99
use PHPStan\Reflection\TrivialParametersAcceptor;
1010

11-
class MagicMethodReflection implements MethodReflection
11+
final class MagicMethodReflection implements MethodReflection
1212
{
13-
/**
14-
* @var string
15-
*/
13+
/** @var string */
1614
private $name;
1715

18-
/**
19-
* @var ClassReflection
20-
*/
16+
/** @var ClassReflection */
2117
private $declaringClass;
2218

2319
public function __construct(ClassReflection $declaringClass, string $name)
@@ -56,13 +52,13 @@ public function getName(): string
5652
return $this->name;
5753
}
5854

59-
/**
60-
* @return \PHPStan\Reflection\ParametersAcceptor[]
61-
*/
62-
public function getVariants(): array
63-
{
64-
return [
65-
new TrivialParametersAcceptor(),
66-
];
67-
}
55+
/**
56+
* @return \PHPStan\Reflection\ParametersAcceptor[]
57+
*/
58+
public function getVariants(): array
59+
{
60+
return [
61+
new TrivialParametersAcceptor(),
62+
];
63+
}
6864
}

src/Reflection/Varien/Object/MagicMethodsReflectionExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010
use Varien_Object;
1111

12-
class MagicMethodsReflectionExtension implements MethodsClassReflectionExtension
12+
final class MagicMethodsReflectionExtension implements MethodsClassReflectionExtension
1313
{
1414
public function hasMethod(ClassReflection $classReflection, string $methodName): bool
1515
{
1616
$magentoMagicMethods = ['get', 'set', 'uns', 'has'];
1717
return $classReflection->isSubclassOf(Varien_Object::class)
18-
&& in_array(substr($methodName, 0, 3), $magentoMagicMethods);
18+
&& \in_array(substr($methodName, 0, 3), $magentoMagicMethods, true);
1919
}
2020

2121
public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
use Mage;
1616
use Mage_Core_Model_Layout;
1717

18-
19-
class HelperMethodsReturnTypeExtension implements DynamicMethodReturnTypeExtension
18+
final class HelperMethodsReturnTypeExtension implements DynamicMethodReturnTypeExtension
2019
{
2120
public function getClass(): string
2221
{
@@ -25,7 +24,7 @@ public function getClass(): string
2524

2625
public function isMethodSupported(MethodReflection $methodReflection): bool
2726
{
28-
return in_array(
27+
return \in_array(
2928
$methodReflection->getName(),
3029
[
3130
'getBlockSingleton',
@@ -34,6 +33,9 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
3433
);
3534
}
3635

36+
/**
37+
* @throws \PHPStan\ShouldNotHappenException
38+
*/
3739
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
3840
{
3941
if (!isset($methodCall->args[0]) || !$methodCall->args[0]->value instanceof String_) {
@@ -45,7 +47,10 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
4547
return new ObjectType($class);
4648
}
4749

48-
private function getClassFromHelperMethod($method, $name)
50+
/**
51+
* @throws \PHPStan\ShouldNotHappenException
52+
*/
53+
private function getClassFromHelperMethod(string $method, string $name): string
4954
{
5055
$config = Mage::getConfig();
5156
switch ($method) {
@@ -54,6 +59,7 @@ private function getClassFromHelperMethod($method, $name)
5459
case 'helper':
5560
return $config->getHelperClassName($name);
5661
}
62+
5763
throw new ShouldNotHappenException();
5864
}
5965
}

src/Type/Mage/HelperMethodsReturnTypeExtension.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
use Mage;
1717

18-
class HelperMethodsReturnTypeExtension implements DynamicStaticMethodReturnTypeExtension
18+
final class HelperMethodsReturnTypeExtension implements DynamicStaticMethodReturnTypeExtension
1919
{
2020
public function getClass(): string
2121
{
@@ -24,7 +24,7 @@ public function getClass(): string
2424

2525
public function isStaticMethodSupported(MethodReflection $methodReflection): bool
2626
{
27-
return in_array(
27+
return \in_array(
2828
$methodReflection->getName(),
2929
[
3030
'getModel',
@@ -36,6 +36,9 @@ public function isStaticMethodSupported(MethodReflection $methodReflection): boo
3636
);
3737
}
3838

39+
/**
40+
* @throws \PHPStan\ShouldNotHappenException
41+
*/
3942
public function getTypeFromStaticMethodCall(MethodReflection $methodReflection, StaticCall $methodCall, Scope $scope): Type
4043
{
4144
if (!isset($methodCall->args[0]) || !$methodCall->args[0]->value instanceof String_) {
@@ -52,7 +55,10 @@ public function getTypeFromStaticMethodCall(MethodReflection $methodReflection,
5255
return new ObjectType($class);
5356
}
5457

55-
private function getClassFromHelperMethod($method, $name)
58+
/**
59+
* @throws \PHPStan\ShouldNotHappenException
60+
*/
61+
private function getClassFromHelperMethod(string $method, string $name)
5662
{
5763
$config = Mage::getConfig();
5864
switch ($method) {
@@ -65,6 +71,7 @@ private function getClassFromHelperMethod($method, $name)
6571
case 'helper':
6672
return $config->getHelperClassName($name);
6773
}
74+
6875
throw new ShouldNotHappenException();
6976
}
7077
}

0 commit comments

Comments
 (0)