Skip to content

Commit

Permalink
Merge pull request #60 from dontub/fix-bump-command-nikolaposa/versio…
Browse files Browse the repository at this point in the history
…n-v3

Make VersionBumpCommand compatible with nikolaposa/version 3
  • Loading branch information
dontub authored Aug 9, 2019
2 parents 441c0b8 + 52cf0b5 commit 757022a
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions Command/VersionBumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,48 +71,55 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln(sprintf('Formatter: <comment>%s</comment>', 'Not available'));
}

// Used for BC compatibility with nikolaposa/version 2.2
$isNikolaposaVersion2 = method_exists($version, 'withMajorIncremented');

$incrementMajor = (int) $input->getOption('major');
if ($incrementMajor > 0) {
for ($i = 0; $i < $incrementMajor; $i++) {
$version = $version->withMajorIncremented();
$version = $isNikolaposaVersion2 ? $version->withMajorIncremented() : $version->incrementMajor();
}
}

$incrementMinor = (int) $input->getOption('minor');
if ($incrementMinor > 0) {
for ($i = 0; $i < $incrementMinor; $i++) {
$version = $version->withMinorIncremented();
$version = $isNikolaposaVersion2 ? $version->withMinorIncremented() : $version->incrementMinor();
}
}

$incrementPatch = (int) $input->getOption('patch');
if ($incrementPatch > 0) {
for ($i = 0; $i < $incrementPatch; $i++) {
$version = $version->withPatchIncremented();
$version = $isNikolaposaVersion2 ? $version->withPatchIncremented() : $version->incrementPatch();
}
}

$preRelease = $input->getOption('prerelease');
if (!empty($preRelease)) {
if (in_array(null, $preRelease)) {
$preRelease = array();
if (in_array(null, $preRelease, true)) {
$preRelease = $isNikolaposaVersion2 ? array() : null;
} else {
$preRelease = implode('.', $preRelease);
}

$version = $version->withPreRelease($preRelease);
}

$build = $input->getOption('build');
if (!empty($build)) {
if (in_array(null, $build)) {
$build = array();
if (in_array(null, $build, true)) {
$build = $isNikolaposaVersion2 ? array() : null;
} else {
$build = implode('.', $build);
}

$version = $version->withBuild($build);
}

$currentVersion = $this->manager->getVersion();
if ((string) $currentVersion == (string) $version) {
$version = $version->withPatchIncremented();
if ((string) $currentVersion === (string) $version) {
$version = $isNikolaposaVersion2 ? $version->withPatchIncremented() : $version->incrementPatch();
}

$output->writeln(sprintf('Current version: <info>%s</info>', $currentVersion));
Expand Down

0 comments on commit 757022a

Please sign in to comment.