Skip to content

Commit e740a41

Browse files
Fixed issues with PHP 8
1 parent df4ff71 commit e740a41

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

phpstan.neon.dist

-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,3 @@ parameters:
2222
-
2323
message: "#^Only booleans are allowed in &&, string given on the left side.$#"
2424
path: src/ArgumentResolver/NamedValueResolver.php
25-
-
26-
message: "#^Parameter \\#1 \\$argument of class ReflectionClass constructor expects class-string<T of object>\\|T of object, string given.$#"
27-
path: src/ArgumentResolver/ClassValueResolver.php

src/ArgumentResolver/ClassValueResolver.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use DivineNii\Invoker\Interfaces\ArgumentValueResolverInterface;
2222
use Psr\Container\ContainerInterface;
2323
use Psr\Container\NotFoundExceptionInterface;
24-
use ReflectionClass;
2524
use ReflectionParameter;
2625

2726
/**
@@ -69,10 +68,8 @@ public function resolve(ReflectionParameter $parameter, array $providedParameter
6968
}
7069

7170
try {
72-
$reflectionClass = new ReflectionClass($parameterType->getName());
73-
74-
if ($reflectionClass->isInstantiable()) {
75-
return $reflectionClass->newInstance();
71+
if (\class_exists($class = $parameterType->getName())) {
72+
return new $class();
7673
}
7774
} catch (ArgumentCountError $e) {
7875
// Throw no exception ...

tests/ArgumentResolverTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public function implicitCallableData(): Generator
199199
yield 'String Callable without variable' => [
200200
'phpinfo',
201201
[],
202-
[],
202+
\PHP_VERSION_ID >= 80000 ? [INFO_ALL] : [],
203203
];
204204

205205
yield 'Callable with named variable' => [

tests/CallableResolverTest.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,15 @@ public function testResolveWithContainerHasNotAndStaticException(): void
164164
$container->method('has')->with(Fixtures\BlankClassMagic::class)->willReturn(false);
165165
$container->method('get')->willThrowException(self::notFoundException());
166166

167-
$this->expectExceptionMessage(
168-
'Cannot call DivineNii\Invoker\Tests\Fixtures\BlankClassMagic::staticMethod() because ' .
169-
'staticMethod() is not a static method and "DivineNii\Invoker\Tests\Fixtures\BlankClassMagic'
170-
);
167+
$exceptionMessage = 'Cannot call DivineNii\Invoker\Tests\Fixtures\BlankClassMagic::staticMethod() because ' .
168+
'staticMethod() is not a static method and "DivineNii\Invoker\Tests\Fixtures\BlankClassMagic';
169+
170+
if (\PHP_VERSION_ID >= 80000) {
171+
$exceptionMessage = 'DivineNii\Invoker\Tests\Fixtures\BlankClassMagic::staticMethod() is not a callable.' .
172+
' A __call() method exists but magic methods are not supported.';
173+
}
174+
175+
$this->expectExceptionMessage($exceptionMessage);
171176
$this->expectException(NotCallableException::class);
172177

173178
$factory = new CallableResolver($container);

0 commit comments

Comments
 (0)