protected function getNextVersion($tag)
{
$nextVersionSuffix = '';
$betaVersionPattern = '/-beta(\\d+)$/';
if (preg_match($betaVersionPattern, $tag, $matches) > 0) {
$tag = preg_replace($betaVersionPattern, '', $tag);
if ($this->tagBetaVersion === false) {
return $tag;
}
if ($this->tagMajorVersion === false && $this->tagMinorVersion == false) {
$nextVersionSuffix = '-beta' . ((int) $matches[1] + 1);
} else {
$nextVersionSuffix = '-beta1';
}
} else {
if ($this->tagBetaVersion === true) {
$nextVersionSuffix = '-beta1';
}
}
$versionPattern = '/^(\\d+)\\.(\\d+)\\.(\\d+)$/';
$increment = function ($position) use($nextVersionSuffix) {
return function ($matches) use($position, $nextVersionSuffix) {
for ($i = 1; $i <= 3; $i++) {
if ($i > $position) {
$matches[$i] = 0;
}
if ($i === $position) {
$matches[$i] += 1;
}
}
return implode('.', array_slice($matches, 1)) . $nextVersionSuffix;
};
};
if ($this->tagMajorVersion === true) {
return preg_replace_callback($versionPattern, $increment(self::majorVersion), $tag);
}
if ($this->tagMinorVersion === true) {
return preg_replace_callback($versionPattern, $increment(self::minorVersion), $tag);
}
if ($this->tagBetaVersion === true && $this->tagMajorVersion === false && $this->tagMajorVersion === false) {
return $tag . $nextVersionSuffix;
}
return preg_replace_callback($versionPattern, $increment(self::patchVersion), $tag);
}