Skip to content

Commit cb2d060

Browse files
committed
Simplify the __debugInfo() condition and cover a PHP version range spanning 8.6 in EnumSanityRule
1 parent 6feaa37 commit cb2d060

3 files changed

Lines changed: 50 additions & 1 deletion

File tree

‎src/Rules/Classes/EnumSanityRule.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function processNode(Node $node, Scope $scope): array
8282
->build();
8383
} elseif (
8484
!array_key_exists($lowercasedMethodName, self::ALLOWED_MAGIC_METHODS)
85-
&& !($lowercasedMethodName === '__debuginfo' && $scope->getPhpVersion()->supportsDebugInfoOnEnums()->yes())
85+
&& ($lowercasedMethodName !== '__debuginfo' || !$scope->getPhpVersion()->supportsDebugInfoOnEnums()->yes())
8686
) {
8787
$errors[] = RuleErrorBuilder::message(sprintf(
8888
'Enum %s contains magic method %s().',
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Rules\Classes;
4+
5+
use PHPStan\Reflection\InitializerExprTypeResolver;
6+
use PHPStan\Rules\Rule;
7+
use PHPStan\Testing\RuleTestCase;
8+
use PHPUnit\Framework\Attributes\RequiresPhp;
9+
10+
/**
11+
* @extends RuleTestCase<EnumSanityRule>
12+
*/
13+
class EnumSanityRuleConfigPhpTest extends RuleTestCase
14+
{
15+
16+
protected function getRule(): Rule
17+
{
18+
return new EnumSanityRule(
19+
self::getContainer()->getByType(InitializerExprTypeResolver::class),
20+
);
21+
}
22+
23+
#[RequiresPhp('>= 8.1.0')]
24+
public function testDebugInfoPhpVersionRangeSpanning86(): void
25+
{
26+
$this->analyse([__DIR__ . '/data/enum-debug-info-php-versions.php'], [
27+
[
28+
'Enum EnumDebugInfoPhpVersions\UnsupportedInBranch contains magic method __debugInfo().',
29+
18,
30+
],
31+
[
32+
'Enum EnumDebugInfoPhpVersions\DependsOnPhpVersion contains magic method __debugInfo().',
33+
27,
34+
],
35+
]);
36+
}
37+
38+
public static function getAdditionalConfigFiles(): array
39+
{
40+
return [
41+
__DIR__ . '/data/enum-debug-info-php-version.neon',
42+
];
43+
}
44+
45+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
phpVersion:
3+
min: 80500
4+
max: 80600

0 commit comments

Comments
 (0)