Skip to content

Commit 44458d8

Browse files
phpstan-botclaude
andcommitted
Fix lint errors and skip testBug7599 on PHP < 8.1
- Use early exit in ConstantConditionRuleHelper to reduce nesting (SlevomatCodingStandard.ControlStructures.EarlyExit) - Use \in_array() instead of fallback global name in ExpressionDependsOnThisHelper (SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly) - Skip testBug7599 on PHP < 8.1 using #[RequiresPhp] attribute (enums require PHP 8.1) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6d73f01 commit 44458d8

3 files changed

Lines changed: 19 additions & 14 deletions

File tree

src/Rules/Comparison/ConstantConditionRuleHelper.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,24 @@ private function shouldSkip(Scope $scope, Expr $expr): bool
6262
return true;
6363
}
6464

65-
if ($scope->isInTrait()) {
66-
foreach ($expr->getArgs() as $arg) {
67-
if (ExpressionDependsOnThisHelper::isExpressionDependentOnThis($arg->value)) {
68-
return true;
69-
}
65+
if (!$scope->isInTrait()) {
66+
return false;
67+
}
68+
69+
foreach ($expr->getArgs() as $arg) {
70+
if (ExpressionDependsOnThisHelper::isExpressionDependentOnThis($arg->value)) {
71+
return true;
72+
}
73+
74+
$classReflection = $scope->getClassReflection();
75+
if ($classReflection === null) {
76+
continue;
77+
}
7078

71-
$classReflection = $scope->getClassReflection();
72-
if ($classReflection !== null) {
73-
$argType = $this->treatPhpDocTypesAsCertain ? $scope->getType($arg->value) : $scope->getNativeType($arg->value);
74-
foreach ($argType->getObjectClassNames() as $className) {
75-
if ($className === $classReflection->getName()) {
76-
return true;
77-
}
78-
}
79+
$argType = $this->treatPhpDocTypesAsCertain ? $scope->getType($arg->value) : $scope->getNativeType($arg->value);
80+
foreach ($argType->getObjectClassNames() as $className) {
81+
if ($className === $classReflection->getName()) {
82+
return true;
7983
}
8084
}
8185
}

src/Rules/Comparison/ExpressionDependsOnThisHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static function isExpressionDependentOnThis(Expr $expr): bool
2727
}
2828

2929
$className = $expr->class->toString();
30-
return in_array($className, ['self', 'static', 'parent'], true);
30+
return \in_array($className, ['self', 'static', 'parent'], true);
3131
}
3232

3333
return false;

tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,7 @@ public function testBug13023(): void
12051205
$this->analyse([__DIR__ . '/data/bug-13023.php'], []);
12061206
}
12071207

1208+
#[RequiresPhp('>= 8.1')]
12081209
public function testBug7599(): void
12091210
{
12101211
$this->treatPhpDocTypesAsCertain = true;

0 commit comments

Comments
 (0)