Skip to content

Commit 15eabe3

Browse files
phpstan-botclaude
andcommitted
Add regression test for class-level isPure check with promoted properties
Verifies that @phpstan-all-methods-pure correctly propagates to methods in classes with promoted constructor properties, even when the method's $resolvedPhpDoc is null. This is a non-regression test for the isPure condition moved outside the `if ($resolvedPhpDoc !== null)` block. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent dbef03c commit 15eabe3

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

tests/PHPStan/Rules/Pure/PureMethodRuleTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,18 @@ public function testAllMethodsArePure(): void
279279
]);
280280
}
281281

282+
#[RequiresPhp('>= 8.0')]
283+
public function testBug14138Pure(): void
284+
{
285+
$this->treatPhpDocTypesAsCertain = true;
286+
$this->analyse([__DIR__ . '/data/bug-14138-pure.php'], [
287+
[
288+
'Impure echo in pure method Bug14138Pure\PureClassWithSideEffect::doSomething().',
289+
31,
290+
],
291+
]);
292+
}
293+
282294
public function testBug12382(): void
283295
{
284296
$this->treatPhpDocTypesAsCertain = true;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php // lint >= 8.0
2+
3+
namespace Bug14138Pure;
4+
5+
/**
6+
* @phpstan-all-methods-pure
7+
*/
8+
class PureClassWithPromotedProperties
9+
{
10+
public function __construct(
11+
protected int $value
12+
) {}
13+
14+
public function getValue(): int
15+
{
16+
return $this->value;
17+
}
18+
}
19+
20+
/**
21+
* @phpstan-all-methods-pure
22+
*/
23+
class PureClassWithSideEffect
24+
{
25+
public function __construct(
26+
protected int $value
27+
) {}
28+
29+
public function doSomething(): int
30+
{
31+
echo 'side effect';
32+
return $this->value;
33+
}
34+
}

0 commit comments

Comments
 (0)