Skip to content

Commit ea28b6b

Browse files
phpstan-botclaude
authored andcommitted
Split trait purity test into dedicated file with RequiresPhp 8.0
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent edf0634 commit ea28b6b

3 files changed

Lines changed: 44 additions & 39 deletions

File tree

tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ public function testBug14563(): void
569569
{
570570
$this->reportMaybes = true;
571571
$this->reportStatic = true;
572-
$errors = [
572+
$this->analyse([__DIR__ . '/data/bug-14563.php'], [
573573
[
574574
'Impure method Bug14563\ChildImpureOverridesPure::pure() overrides pure method Bug14563\Foo::pure().',
575575
31,
@@ -582,42 +582,44 @@ public function testBug14563(): void
582582
'Impure method Bug14563\ImpureChildOfAllMethodsPure::method() overrides pure method Bug14563\AllMethodsPureParent::method().',
583583
126,
584584
],
585-
];
586-
587-
if (PHP_VERSION_ID >= 80000) {
588-
$errors[] = [
589-
'Impure method Bug14563\ImpureTraitUser::pureTraitMethod() overrides pure method Bug14563\PureTrait::pureTraitMethod().',
590-
147,
591-
];
592-
}
593-
594-
$errors = array_merge($errors, [
595585
[
596586
'Impure method Bug14563\ChildImpureOverridesPureExtended::pure() overrides pure method Bug14563\Foo::pure().',
597-
158,
587+
137,
598588
],
599589
[
600590
'Impure method Bug14563\GrandchildImpureOverridesPure::pure() overrides pure method Bug14563\ChildPureOverridesPure::pure().',
601-
169,
591+
148,
602592
],
603593
[
604594
'Impure method Bug14563\ImpureMultipleInterfaces::sharedMethod() overrides pure method Bug14563\PureInterfaceA::sharedMethod().',
605-
207,
595+
186,
606596
],
607597
[
608598
'Impure method Bug14563\ImpureMultipleInterfaces::sharedMethod() overrides pure method Bug14563\PureInterfaceB::sharedMethod().',
609-
207,
599+
186,
610600
],
611601
[
612602
'Impure method Bug14563\StaticChildImpureOverridesPure::pure() overrides pure method Bug14563\StaticFoo::pure().',
613-
240,
603+
219,
614604
],
615605
[
616606
'Impure method Bug14563\StaticImpureImplementation::pureMethod() overrides pure method Bug14563\StaticPureInterface::pureMethod().',
617-
291,
607+
270,
608+
],
609+
]);
610+
}
611+
612+
#[RequiresPhp('>= 8.0.0')]
613+
public function testBug14563Trait(): void
614+
{
615+
$this->reportMaybes = true;
616+
$this->reportStatic = true;
617+
$this->analyse([__DIR__ . '/data/bug-14563-trait.php'], [
618+
[
619+
'Impure method Bug14563Trait\ImpureTraitUser::pureTraitMethod() overrides pure method Bug14563Trait\PureTrait::pureTraitMethod().',
620+
19,
618621
],
619622
]);
620-
$this->analyse([__DIR__ . '/data/bug-14563.php'], $errors);
621623
}
622624

623625
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug14563Trait;
4+
5+
trait PureTrait
6+
{
7+
8+
/** @phpstan-pure */
9+
abstract public function pureTraitMethod(): int;
10+
11+
}
12+
13+
class ImpureTraitUser
14+
{
15+
16+
use PureTrait;
17+
18+
/** @phpstan-impure */
19+
public function pureTraitMethod(): int
20+
{
21+
return random_int(0, 1);
22+
}
23+
24+
}

tests/PHPStan/Rules/Methods/data/bug-14563.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -130,27 +130,6 @@ public function method(): int
130130

131131
}
132132

133-
trait PureTrait
134-
{
135-
136-
/** @phpstan-pure */
137-
abstract public function pureTraitMethod(): int;
138-
139-
}
140-
141-
class ImpureTraitUser
142-
{
143-
144-
use PureTrait;
145-
146-
/** @phpstan-impure */
147-
public function pureTraitMethod(): int
148-
{
149-
return random_int(0, 1);
150-
}
151-
152-
}
153-
154133
class ChildImpureOverridesPureExtended extends Foo
155134
{
156135

0 commit comments

Comments
 (0)