Skip to content

Commit 9544f8a

Browse files
committed
Do not complain about impure(Function|Method).pure if it has @phpstan-assert tags
1 parent d5a4746 commit 9544f8a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Rules/Pure/FunctionPurityCheck.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ public function check(
8989
->build();
9090
}
9191
} elseif ($isPure->no()) {
92-
if (count($impurePoints) === 0) {
92+
if (
93+
count($throwPoints) === 0
94+
&& count($impurePoints) === 0
95+
&& count($functionReflection->getAsserts()->getAll()) === 0
96+
) {
9397
$errors[] = RuleErrorBuilder::message(sprintf(
9498
'%s is marked as impure but does not have any side effects.',
9599
$functionDescription,

tests/PHPStan/Rules/Pure/data/pure-method.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,18 @@ private function doBaz(): void
360360
}
361361

362362
}
363+
364+
class AssertingImpureVoidMethod
365+
{
366+
367+
/**
368+
* @param mixed $value
369+
* @phpstan-assert array $value
370+
* @phpstan-impure
371+
*/
372+
public function assertSth($value): void
373+
{
374+
375+
}
376+
377+
}

0 commit comments

Comments
 (0)