Skip to content

Commit 020f7b4

Browse files
committed
Fix CS
1 parent 66d07c1 commit 020f7b4

8 files changed

Lines changed: 45 additions & 11 deletions

File tree

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
.php-cs-fixer.php export-ignore
66
Makefile export-ignore
77
phpstan.neon export-ignore
8+
phpstan-baseline.neon export-ignore
89
phpunit.xml export-ignore

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@
4242
"laminas/laminas-i18n": "^2.11.2",
4343
"laminas/laminas-inputfilter": "^2.12.0",
4444
"laminas/laminas-log": "^2.13.1",
45-
"laminas/laminas-mail": "^2.14.1",
45+
"laminas/laminas-mail": "^2.15.0",
4646
"laminas/laminas-mvc": "^3.2.0",
4747
"laminas/laminas-paginator": "^2.10.0",
4848
"laminas/laminas-validator": "^2.15.0",
4949
"malukenho/mcbumpface": "^1.1.5",
5050
"phpstan/phpstan-phpunit": "^0.12.22",
5151
"phpunit/phpunit": "^9.5.9",
52-
"slam/php-cs-fixer-extensions": "^v3.0.1",
52+
"slam/php-cs-fixer-extensions": "^v3.1.0",
5353
"slam/php-debug-r": "^v1.7.0"
5454
},
5555
"extra": {

phpstan-baseline.neon

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Parameter \\#2 \\$args of static method PHPStan\\\\Reflection\\\\ParametersAcceptorSelector\\:\\:selectFromArgs\\(\\) expects array\\<PhpParser\\\\Node\\\\Arg\\>, array\\<PhpParser\\\\Node\\\\Arg\\|PhpParser\\\\Node\\\\VariadicPlaceholder\\> given\\.$#"
5+
count: 1
6+
path: src/Type/Laminas/PluginMethodDynamicReturnTypeExtension/AbstractPluginMethodDynamicReturnTypeExtension.php
7+

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
includes:
22
- vendor/phpstan/phpstan-phpunit/extension.neon
3+
- phpstan-baseline.neon
34

45
parameters:
56
level: max

src/Rules/Laminas/ServiceManagerGetMethodCallRule.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use LaminasPhpStan\ServiceManagerLoader;
1111
use LaminasPhpStan\Type\Laminas\ObjectServiceManagerType;
1212
use PhpParser\Node;
13+
use PhpParser\Node\Arg;
1314
use PHPStan\Analyser\Scope;
1415
use PHPStan\Broker\Broker;
1516
use PHPStan\Rules\Rule;
@@ -49,7 +50,11 @@ public function processNode(Node $node, Scope $scope): array
4950
return [];
5051
}
5152

52-
$argType = $scope->getType($node->args[0]->value);
53+
$firstArg = $node->args[0];
54+
if (! $firstArg instanceof Arg) {
55+
return [];
56+
}
57+
$argType = $scope->getType($firstArg->value);
5358
if (! $argType instanceof ConstantStringType) {
5459
return [];
5560
}
@@ -100,7 +105,7 @@ public function processNode(Node $node, Scope $scope): array
100105
)];
101106
}
102107

103-
protected function isTypeInstanceOfContainer(ObjectType $type): bool
108+
private function isTypeInstanceOfContainer(ObjectType $type): bool
104109
{
105110
return $type->isInstanceOf(ServiceLocatorInterface::class)->yes()
106111
|| $type->isInstanceOf(InteropContainerInterface::class)->yes()

src/Type/Laminas/PluginMethodDynamicReturnTypeExtension/AbstractPluginMethodDynamicReturnTypeExtension.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace LaminasPhpStan\Type\Laminas\PluginMethodDynamicReturnTypeExtension;
66

77
use LaminasPhpStan\ServiceManagerLoader;
8+
use PhpParser\Node\Arg;
89
use PhpParser\Node\Expr\MethodCall;
910
use PHPStan\Analyser\Scope;
1011
use PHPStan\Reflection\MethodReflection;
@@ -35,7 +36,16 @@ final public function getTypeFromMethodCall(
3536
MethodCall $methodCall,
3637
Scope $scope
3738
): Type {
38-
$argType = $scope->getType($methodCall->args[0]->value);
39+
$firstArg = $methodCall->args[0];
40+
if (! $firstArg instanceof Arg) {
41+
throw new \PHPStan\ShouldNotHappenException(\sprintf(
42+
'Argument passed to %s::%s should be a string, %s given',
43+
$methodReflection->getDeclaringClass()->getName(),
44+
$methodReflection->getName(),
45+
$firstArg->getType()
46+
));
47+
}
48+
$argType = $scope->getType($firstArg->value);
3949
$strings = TypeUtils::getConstantStrings($argType);
4050
$plugin = 1 === \count($strings) ? $strings[0]->getValue() : null;
4151

src/Type/Laminas/ServiceManagerGetDynamicReturnTypeExtension.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Laminas\ServiceManager\AbstractPluginManager;
88
use Laminas\ServiceManager\ServiceLocatorInterface;
99
use LaminasPhpStan\ServiceManagerLoader;
10+
use PhpParser\Node\Arg;
1011
use PhpParser\Node\Expr\MethodCall;
1112
use PHPStan\Analyser\Scope;
1213
use PHPStan\Broker\Broker;
@@ -62,7 +63,16 @@ public function getTypeFromMethodCall(
6263

6364
$serviceManager = $this->serviceManagerLoader->getServiceLocator($calledOnType->getClassName());
6465

65-
$argType = $scope->getType($methodCall->args[0]->value);
66+
$firstArg = $methodCall->args[0];
67+
if (! $firstArg instanceof Arg) {
68+
throw new \PHPStan\ShouldNotHappenException(\sprintf(
69+
'Argument passed to %s::%s should be a string, %s given',
70+
$methodReflection->getDeclaringClass()->getName(),
71+
$methodReflection->getName(),
72+
$firstArg->getType()
73+
));
74+
}
75+
$argType = $scope->getType($firstArg->value);
6676
if (! $argType instanceof ConstantStringType) {
6777
if ($serviceManager instanceof AbstractPluginManager) {
6878
$refClass = new ReflectionClass($serviceManager);

tests/Rules/Laminas/ServiceManagerGetMethodCallRuleTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ final class ServiceManagerGetMethodCallRuleTest extends RuleTestCase
2121
{
2222
private ServiceManagerLoader $serviceManagerLoader;
2323

24+
protected function setUp(): void
25+
{
26+
$this->serviceManagerLoader = new ServiceManagerLoader(null);
27+
}
28+
2429
/**
2530
* @return string[][]
2631
*/
@@ -33,11 +38,6 @@ public function provideContainerTypes(): array
3338
];
3439
}
3540

36-
protected function setUp(): void
37-
{
38-
$this->serviceManagerLoader = new ServiceManagerLoader(null);
39-
}
40-
4141
/**
4242
* @return Rule<\PhpParser\Node\Expr\MethodCall>
4343
*/

0 commit comments

Comments
 (0)