Skip to content

Commit 717ac20

Browse files
committed
fix: phpstan errors
1 parent a3fe677 commit 717ac20

3 files changed

Lines changed: 16 additions & 19 deletions

File tree

src/Rule/MethodBecomesAbstractRule.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
*/
1919
class MethodBecomesAbstractRule implements Rule
2020
{
21-
public function __construct(private readonly ReflectionProvider $reflectionProvider)
22-
{
23-
}
21+
public function __construct(private readonly ReflectionProvider $reflectionProvider) {}
2422

2523
public function getNodeType(): string
2624
{
@@ -41,17 +39,23 @@ public function processNode(Node $node, Scope $scope): array
4139

4240
foreach ($node->stmts as $stmt) {
4341
if ($stmt instanceof ClassMethod) {
44-
$existingMethods[] = (string)$stmt->name;
42+
$existingMethods[] = (string) $stmt->name;
4543
}
4644
}
4745

4846
/** @var ClassReflection $parent */
4947
foreach ([$extendedClass, ...$extendedClass->getParents()] as $parent) {
5048
foreach ($parent->getNativeReflection()->getMethods() as $method) {
49+
$docComment = $method->getDocComment();
50+
51+
if ($docComment === false) {
52+
continue;
53+
}
54+
5155
if (
5256
!$method->isAbstract() &&
5357
($method->isPublic() || $method->isProtected()) &&
54-
str_contains($method->getDocComment(), '@abstract') &&
58+
str_contains($docComment, '@abstract') &&
5559
!in_array($method->getName(), $existingMethods, true)
5660
) {
5761
$errors[] = RuleErrorBuilder::message(sprintf('Method %s::%s becomes abstract, but is not declared in the extending class. Implement the method for compatibility with next major version.', $parent->getName(), $method->getName()))
@@ -65,4 +69,4 @@ public function processNode(Node $node, Scope $scope): array
6569

6670
return $errors;
6771
}
68-
}
72+
}

tests/Rule/MethodBecomesAbstractRuleTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function testAnalyse(): void
2020
<<<EOF
2121
Method EntityExtension::new becomes abstract, but is not declared in the extending class. Implement the method for compatibility with next major version.
2222
EOF,
23-
18,
23+
13,
2424
],
2525
]);
2626
}
@@ -41,4 +41,4 @@ protected function getRule(): Rule
4141
{
4242
return new MethodBecomesAbstractRule(self::createReflectionProvider());
4343
}
44-
}
44+
}

tests/data/MethodBecomesAbstractRule/impl.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,15 @@
22

33
class EntityExtension
44
{
5-
public function old(): void
6-
{
7-
}
5+
public function old(): void {}
86

97
/**
108
* @abstract
119
*/
12-
public function new(): void
13-
{
14-
15-
}
10+
public function new(): void {}
1611
}
1712

1813
class Impl extends EntityExtension
1914
{
20-
public function old(): void
21-
{
22-
}
23-
}
15+
public function old(): void {}
16+
}

0 commit comments

Comments
 (0)