Skip to content

Commit

Permalink
Removed some errors from RequireParentConstructCallRule - already rep…
Browse files Browse the repository at this point in the history
…orted by PHPStan core
  • Loading branch information
ondrejmirtes committed Jun 9, 2023
1 parent bd3aa8b commit 872bc91
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 37 deletions.
38 changes: 11 additions & 27 deletions src/Rules/Classes/RequireParentConstructCallRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,34 +50,18 @@ public function processNode(Node $node, Scope $scope): array
}

if ($this->callsParentConstruct($node)) {
if ($classReflection->getParentClass() === false) {
return [
RuleErrorBuilder::message(sprintf(
'%s::__construct() calls parent constructor but does not extend any class.',
$classReflection->getName()
))->build(),
];
}
return [];
}

if ($this->getParentConstructorClass($classReflection) === false) {
return [
RuleErrorBuilder::message(sprintf(
'%s::__construct() calls parent constructor but parent does not have one.',
$classReflection->getName()
))->build(),
];
}
} else {
$parentClass = $this->getParentConstructorClass($classReflection);
if ($parentClass !== false) {
return [
RuleErrorBuilder::message(sprintf(
'%s::__construct() does not call parent constructor from %s.',
$classReflection->getName(),
$parentClass->getName()
))->build(),
];
}
$parentClass = $this->getParentConstructorClass($classReflection);
if ($parentClass !== false) {
return [
RuleErrorBuilder::message(sprintf(
'%s::__construct() does not call parent constructor from %s.',
$classReflection->getName(),
$parentClass->getName()
))->build(),
];
}

return [];
Expand Down
11 changes: 1 addition & 10 deletions tests/Rules/Classes/RequireParentConstructCallRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ protected function getRule(): Rule
public function testCallToParentConstructor(): void
{
$this->analyse([__DIR__ . '/data/call-to-parent-constructor.php'], [
[
'IpsumCallToParentConstructor::__construct() calls parent constructor but parent does not have one.',
31,
],
[
'BCallToParentConstructor::__construct() does not call parent constructor from ACallToParentConstructor.',
51,
Expand Down Expand Up @@ -53,12 +49,7 @@ public function testCallsParentButHasNotParent(): void
if (PHP_VERSION_ID >= 70400) {
self::markTestSkipped('This test does not support PHP 7.4 or higher.');
}
$this->analyse([__DIR__ . '/data/call-to-parent-constructor-php-lt-74.php'], [
[
'CCallToParentConstructor::__construct() calls parent constructor but does not extend any class.',
6,
],
]);
$this->analyse([__DIR__ . '/data/call-to-parent-constructor-php-lt-74.php'], []);
}

}

0 comments on commit 872bc91

Please sign in to comment.