Skip to content

Commit 872bc91

Browse files
committed
Removed some errors from RequireParentConstructCallRule - already reported by PHPStan core
1 parent bd3aa8b commit 872bc91

File tree

2 files changed

+12
-37
lines changed

2 files changed

+12
-37
lines changed

src/Rules/Classes/RequireParentConstructCallRule.php

+11-27
Original file line numberDiff line numberDiff line change
@@ -50,34 +50,18 @@ public function processNode(Node $node, Scope $scope): array
5050
}
5151

5252
if ($this->callsParentConstruct($node)) {
53-
if ($classReflection->getParentClass() === false) {
54-
return [
55-
RuleErrorBuilder::message(sprintf(
56-
'%s::__construct() calls parent constructor but does not extend any class.',
57-
$classReflection->getName()
58-
))->build(),
59-
];
60-
}
53+
return [];
54+
}
6155

62-
if ($this->getParentConstructorClass($classReflection) === false) {
63-
return [
64-
RuleErrorBuilder::message(sprintf(
65-
'%s::__construct() calls parent constructor but parent does not have one.',
66-
$classReflection->getName()
67-
))->build(),
68-
];
69-
}
70-
} else {
71-
$parentClass = $this->getParentConstructorClass($classReflection);
72-
if ($parentClass !== false) {
73-
return [
74-
RuleErrorBuilder::message(sprintf(
75-
'%s::__construct() does not call parent constructor from %s.',
76-
$classReflection->getName(),
77-
$parentClass->getName()
78-
))->build(),
79-
];
80-
}
56+
$parentClass = $this->getParentConstructorClass($classReflection);
57+
if ($parentClass !== false) {
58+
return [
59+
RuleErrorBuilder::message(sprintf(
60+
'%s::__construct() does not call parent constructor from %s.',
61+
$classReflection->getName(),
62+
$parentClass->getName()
63+
))->build(),
64+
];
8165
}
8266

8367
return [];

tests/Rules/Classes/RequireParentConstructCallRuleTest.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ protected function getRule(): Rule
2020
public function testCallToParentConstructor(): void
2121
{
2222
$this->analyse([__DIR__ . '/data/call-to-parent-constructor.php'], [
23-
[
24-
'IpsumCallToParentConstructor::__construct() calls parent constructor but parent does not have one.',
25-
31,
26-
],
2723
[
2824
'BCallToParentConstructor::__construct() does not call parent constructor from ACallToParentConstructor.',
2925
51,
@@ -53,12 +49,7 @@ public function testCallsParentButHasNotParent(): void
5349
if (PHP_VERSION_ID >= 70400) {
5450
self::markTestSkipped('This test does not support PHP 7.4 or higher.');
5551
}
56-
$this->analyse([__DIR__ . '/data/call-to-parent-constructor-php-lt-74.php'], [
57-
[
58-
'CCallToParentConstructor::__construct() calls parent constructor but does not extend any class.',
59-
6,
60-
],
61-
]);
52+
$this->analyse([__DIR__ . '/data/call-to-parent-constructor-php-lt-74.php'], []);
6253
}
6354

6455
}

0 commit comments

Comments
 (0)