Skip to content

Commit 09cf2d2

Browse files
committed
Fix prerelease increment logic to handle numeric values correctly
1 parent 9d93d0b commit 09cf2d2

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

app/Commands/IncrementCommand.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
use Throwable;
1515
use Version\Version;
1616

17+
use function is_numeric;
1718
use function is_string;
1819
use function sprintf;
20+
use function trim;
1921

2022
final class IncrementCommand extends Command
2123
{
@@ -116,9 +118,14 @@ private function increment(Version $version, string $part, $pre = null, $build =
116118
}
117119

118120
$identifier = $currentPrerelease->getIdentifiers();
119-
$preTag = $identifier[0];
120-
$preVersion = (int) ($identifier[1] ?? 0) + 1;
121-
$version = $version->withPreRelease(sprintf('%s.%d', $preTag, $preVersion));
121+
$preTag = isset($identifier[0]) && is_string($identifier[0]) ? trim($identifier[0]) : null;
122+
123+
if ($preTag === null || $preTag === '') {
124+
throw new InvalidArgumentException('Unable to determine the prerelease tag for incrementing.');
125+
}
126+
127+
$preVersion = isset($identifier[1]) && is_numeric($identifier[1]) ? (int) $identifier[1] : 0;
128+
$version = $version->withPreRelease(sprintf('%s.%d', $preTag, $preVersion + 1));
122129

123130
break;
124131

0 commit comments

Comments
 (0)