Skip to content

Commit b8b0e28

Browse files
VincentLangletondrejmirtes
authored andcommitted
Rework
1 parent d69f930 commit b8b0e28

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Reflection/InitializerExprTypeResolver.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
use function max;
118118
use function min;
119119
use function sprintf;
120+
use function str_starts_with;
120121
use function strtolower;
121122
use const INF;
122123

@@ -588,9 +589,9 @@ public function resolveConcatType(Type $left, Type $right): Type
588589

589590
$leftNumericStringNonEmpty = TypeCombinator::remove($leftStringType, new ConstantStringType(''));
590591
if ($leftNumericStringNonEmpty->isNumericString()->yes()) {
591-
$allowedRightPattern = $left->isInteger()->yes()
592-
? '#^(\d+|\d+.\d+)([eE][+-]?\d+)?$#' // non-negative integer, float or scientific string
593-
: '#^\d+$#'; // non-negative integer string
592+
$validationCallback = $left->isInteger()->yes()
593+
? static fn (string $value): bool => !str_starts_with($value, '-')
594+
: static fn (string $value): bool => Strings::match($value, '#^\d+$#') !== null;
594595

595596
$allRightConstantsZeroOrMore = false;
596597
foreach ($rightConstantStrings as $rightConstantString) {
@@ -600,7 +601,7 @@ public function resolveConcatType(Type $left, Type $right): Type
600601

601602
if (
602603
!is_numeric($rightConstantString->getValue())
603-
|| Strings::match($rightConstantString->getValue(), $allowedRightPattern) === null
604+
|| !$validationCallback($rightConstantString->getValue())
604605
) {
605606
$allRightConstantsZeroOrMore = false;
606607
break;

0 commit comments

Comments
 (0)