Skip to content

Commit 998d101

Browse files
phpstan-botclaude
authored andcommitted
Add test for dynamic static call on object instance (MyEnum $enum)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 24e0653 commit 998d101

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

tests/PHPStan/Rules/Pure/PureMethodRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public function testBug14557(): void
396396
$this->analyse([__DIR__ . '/data/bug-14557.php'], [
397397
[
398398
'Impure call to method Bug14557\SomeClass::impureStaticMethod() in pure method Bug14557\Foo::impureViaClassString().',
399-
85,
399+
93,
400400
],
401401
]);
402402
}

tests/PHPStan/Rules/Pure/data/bug-14557-function.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,11 @@ function tryFromClassString(string $enum): ?MyEnum
4545
{
4646
return $enum::tryFrom('foo');
4747
}
48+
49+
/**
50+
* @phpstan-pure
51+
*/
52+
function fromEnum(MyEnum $enum): MyEnum
53+
{
54+
return $enum::from('foo');
55+
}

tests/PHPStan/Rules/Pure/data/bug-14557.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ public function doLorem(string $enum): ?MyEnum
6767
return $enum::tryFrom('foo');
6868
}
6969

70+
/**
71+
* @phpstan-pure
72+
*/
73+
public function fromEnum(MyEnum $enum): MyEnum
74+
{
75+
return $enum::from('foo');
76+
}
77+
7078
/**
7179
* @param class-string<SomeClass> $class
7280
* @phpstan-pure

0 commit comments

Comments
 (0)