Parent call inside a try-catch block(which is always executed) isn't recognised.
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start with PHPStan\Rules\PHPUnit\ShouldCallParentMethodsRule::hasParentClassCall and the shown tearDown() example, focusing on how the try-catch block is traversed. Done means the parent::tearDown() call inside the try-catch is recognised and the missing-call error is no longer reported.
Written by the indexing model from the issue text.
Description
So, I am overriding tearDown() and as the rule suggests i need to call the parent::teardown() inside it , the only problem here is that i want to call it from a try-catch block which phpstan-phpunit doesn't recognise as a valid call to the parent method.
/**
{@inheritdoc}
*/
protected function tearDown(): void {
try {
parent::tearDown();
}
catch (\Exception $exception) {
if (!(get_class($exception) === get_class($this->expectedTearDownException) && $exception->getMessage() ===
$this->expectedTearDownException->getMessage())) {
throw $exception;
}
}
}
phpstan doesn't have this bug i checked in independently https://phpstan.org/r/1a212fa2-3cba-4c82-80db-7c75a8346f50
The main issue seems to be in
$hasParentCall = $this->hasParentClassCall($node->getOriginalNode()->getStmts(), strtolower($methodName));
if (!$hasParentCall) {
return [
RuleErrorBuilder::message(
sprintf('Missing call to parent::%s() method.', $methodName)
)->build(),
];
}
Mainly \PHPStan\Rules\PHPUnit\ShouldCallParentMethodsRule::hasParentClassCall
I think this lacks the logic to detect parent class calls inside a try-catch block.
- Dominant language
- PHP
- Stars
- 544
- Forks
- 58
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 5
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from phpstan/phpstan-phpunit
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 68/100
phpstan/phpstan-phpunit#332 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
phpstan/phpstan-phpunit#321 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
phpstan/phpstan-phpunit#309 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
phpstan/phpstan-phpunit#299 · 2 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
phpstan/phpstan-phpunit#292 · 3 comments ·
All issues in phpstan/phpstan-phpunit
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
pluginsGLPI/datainjection#673 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
octobercms/october#6130 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
getgrav/grav-plugin-form#656 ·
-
customer-support needs-triage Platform(Default)
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
sync-en
Difficulty 1/5 1-3 hours Newbie friendliness 88/100