Skip to content

Commit

Permalink
Do not complain about impure(Function|Method).pure if it has `@phps…
Browse files Browse the repository at this point in the history
…tan-assert` tags
  • Loading branch information
ondrejmirtes committed May 13, 2024
1 parent d5a4746 commit 9544f8a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Rules/Pure/FunctionPurityCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ public function check(
->build();
}
} elseif ($isPure->no()) {
if (count($impurePoints) === 0) {
if (
count($throwPoints) === 0
&& count($impurePoints) === 0
&& count($functionReflection->getAsserts()->getAll()) === 0
) {
$errors[] = RuleErrorBuilder::message(sprintf(
'%s is marked as impure but does not have any side effects.',
$functionDescription,
Expand Down
15 changes: 15 additions & 0 deletions tests/PHPStan/Rules/Pure/data/pure-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,18 @@ private function doBaz(): void
}

}

class AssertingImpureVoidMethod
{

/**
* @param mixed $value
* @phpstan-assert array $value
* @phpstan-impure
*/
public function assertSth($value): void
{

}

}

0 comments on commit 9544f8a

Please sign in to comment.