Skip to content

Commit df4ff71

Browse files
Fixed phpstan, cs and psalm issues
1 parent ef65bb5 commit df4ff71

7 files changed

+25
-19
lines changed

phpstan.neon.dist

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ parameters:
1010
-
1111
message: "#^Construct empty\\(\\) is not allowed. Use more strict comparison.$#"
1212
path: src/ArgumentResolver.php
13-
-
14-
message: "#^Parameter \\#1 \\$object of function get_class expects object, array<int, string> given.$#"
15-
path: src/CallableReflection.php
1613
-
1714
message: "#^Construct empty\\(\\) is not allowed. Use more strict comparison.$#"
1815
path: src/Invoker.php

psalm.xml.dist

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@
3535
</errorLevel>
3636
</InvalidCatch>
3737

38+
<InvalidArrayOffset>
39+
<errorLevel type="suppress">
40+
<file name="src/CallableReflection.php"/>
41+
</errorLevel>
42+
</InvalidArrayOffset>
43+
44+
<InvalidArrayAccess>
45+
<errorLevel type="suppress">
46+
<file name="src/CallableReflection.php"/>
47+
</errorLevel>
48+
</InvalidArrayAccess>
49+
3850
<ArgumentTypeCoercion>
3951
<errorLevel type="suppress">
4052
<referencedFunction name="ReflectionClass::__construct"/>

src/CallableReflection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static function create($callable): ReflectionFunctionAbstract
5555
if (!\is_callable($callable)) {
5656
throw new NotCallableException(\sprintf(
5757
'%s is not a callable',
58-
\is_string($callable) ? $callable : 'Instance of ' . \get_class($callable)
58+
\is_object($callable) ? 'Instance of ' . \get_class($callable) : var_export($callable, true)
5959
));
6060
}
6161

src/CallableResolver.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ public function resolve($callable)
8181
}
8282

8383
/**
84-
* @param array<mixed,string>|object|string $callable
85-
* @param bool $isStaticCallToNonStaticMethod
84+
* @param array<mixed,string>|callable|object|string $callable
85+
* @param bool $isStaticCallToNonStaticMethod
8686
*
8787
* @throws NotCallableException
8888
*
89-
* @return array<mixed,string>|callable|string
89+
* @return callable
9090
*/
9191
private function resolveCallable($callable, bool $isStaticCallToNonStaticMethod)
9292
{
@@ -104,7 +104,7 @@ private function resolveCallable($callable, bool $isStaticCallToNonStaticMethod)
104104
if (null !== $this->container) {
105105
// Replace the container entry name by the actual object
106106
$class = $this->container->get($class);
107-
} elseif (\is_string($class) && \class_exists($class)) {
107+
} elseif (\class_exists($class)) {
108108
$class = new $class();
109109
}
110110

@@ -113,8 +113,8 @@ private function resolveCallable($callable, bool $isStaticCallToNonStaticMethod)
113113
if ($isStaticCallToNonStaticMethod) {
114114
throw new NotCallableException(\sprintf(
115115
'Cannot call %s::%s() because %2$s() is not a static method and "%1$s" is not a valid',
116-
$callable[0],
117-
$callable[1]
116+
$class,
117+
$method
118118
), 0, $e);
119119
}
120120

src/Exceptions/NotCallableException.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
namespace DivineNii\Invoker\Exceptions;
1919

20-
use Psr\Container\ContainerExceptionInterface;
21-
use Throwable;
22-
2320
/**
2421
* The given callable is not actually callable.
2522
*
@@ -28,9 +25,9 @@
2825
class NotCallableException extends InvocationException
2926
{
3027
/**
31-
* @param mixed $value
32-
* @param bool $containerEntry
33-
* @param ContainerExceptionInterface|Throwable $previous
28+
* @param mixed $value
29+
* @param bool $containerEntry
30+
* @param \Throwable $previous
3431
*
3532
* @return InvocationException
3633
*/

tests/CallableReflectionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testCreateCatchReflectionException(): void
7070

7171
public function testCreateNotCallableException(): void
7272
{
73-
$this->expectExceptionMessage('handler is not a callable');
73+
$this->expectExceptionMessage('\'handler\' is not a callable');
7474
$this->expectException(NotCallableException::class);
7575

7676
CallableReflection::create('handler');

tests/CallableResolverTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public function testResolveWithContainerAndMagicException($hasContainer): void
212212
public function testResolveWithContainerHasNotException(): void
213213
{
214214
$container = $this->createMock(ContainerInterface::class);
215-
$newException = new class('is not a callable, none.') extends InvocationException {
215+
$newException = new class ('is not a callable, none.') extends InvocationException {
216216
};
217217

218218
$container->method('has')->willReturn(false);
@@ -327,7 +327,7 @@ function (string $something): string {
327327
*/
328328
public static function notFoundException()
329329
{
330-
return new class('Is not a callable, yeah.') extends Exception implements NotFoundExceptionInterface {
330+
return new class ('Is not a callable, yeah.') extends Exception implements NotFoundExceptionInterface {
331331
};
332332
}
333333
}

0 commit comments

Comments
 (0)