Skip to content

Commit 41ef1a1

Browse files
committed
Update PHPStan and fix static failures
1 parent c8ded7d commit 41ef1a1

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Exercise/PhpPromotion.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpSchool\PHP8Appreciate\Exercise;
66

7+
use PhpParser\Node\Stmt;
78
use PhpParser\Node\Stmt\Class_;
89
use PhpParser\NodeFinder;
910
use PhpParser\Parser;
@@ -54,17 +55,18 @@ public function getArgs(): array
5455

5556
public function check(Input $input): ResultInterface
5657
{
58+
/** @var array<Stmt> $statements */
5759
$statements = $this->parser->parse((string) file_get_contents($input->getRequiredArgument('program')));
60+
/** @var Class_|null $classNode */
61+
$classNode = (new NodeFinder())->findFirstInstanceOf($statements, Class_::class);
5862

59-
/** @var Class_|null $node */
60-
$className = (new NodeFinder())->findFirstInstanceOf($statements, Class_::class)?->name->name;
61-
62-
if (null === $className) {
63+
if (null === $classNode || null === $className = $classNode->name?->name) {
6364
return Failure::fromNameAndReason($this->getName(), 'No class was found');
6465
}
6566

6667
(static fn () => require $input->getRequiredArgument('program'))();
6768

69+
/** @var class-string $className */
6870
$reflectionClass = new ReflectionClass($className);
6971
$params = collect($reflectionClass->getMethod('__construct')->getParameters());
7072
$params = $params->flatMap(fn (\ReflectionParameter $prop) => [$prop->getName() => $prop]);
@@ -138,6 +140,7 @@ public function check(Input $input): ResultInterface
138140
])
139141
->getArrayCopy();
140142

143+
/** @var array{string?: string} $dataFailures */
141144
$dataFailures = array_filter([
142145
'visitor' => $args['visitor'] !== $actual['visitor'],
143146
'key' => $args['key'] !== $actual['key'],
@@ -169,7 +172,7 @@ private function getPropertyType(\ReflectionProperty $prop): string
169172
$type = $prop->getType();
170173

171174
if (null === $type || !$type instanceof \ReflectionNamedType) {
172-
throw new \RuntimeException('Invalid property "%s"', $prop->getName());
175+
throw new \RuntimeException(sprintf('Invalid property "%s"', $prop->getName()));
173176
}
174177
/** @var \ReflectionNamedType $type */
175178
return $type->getName();

0 commit comments

Comments
 (0)