Skip to content

Commit 05d88e7

Browse files
phpstan-botclaude
andcommitted
Add PhpVersion::updatesAutoIncrementKeyForNegativeValues() method
Replace inline version check with a dedicated PhpVersion method for the PHP 8.3+ negative array auto-index behavior. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9f829c3 commit 05d88e7

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/Php/PhpVersion.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,4 +511,9 @@ public function throwsOnStringCast(): bool
511511
return $this->versionId >= 70400;
512512
}
513513

514+
public function updatesAutoIncrementKeyForNegativeValues(): bool
515+
{
516+
return $this->versionId >= 80300;
517+
}
518+
514519
}

src/Type/Constant/ConstantArrayTypeBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $opt
212212

213213
if (
214214
$offsetValue >= $max
215-
|| ($offsetValue < 0 && $max === 0 && PhpVersionStaticAccessor::getInstance()->getVersionId() >= 80300)
215+
|| ($offsetValue < 0 && $max === 0 && PhpVersionStaticAccessor::getInstance()->updatesAutoIncrementKeyForNegativeValues())
216216
) {
217217
/** @var int|float $newAutoIndex */
218218
$newAutoIndex = $offsetValue + 1;

0 commit comments

Comments
 (0)