Skip to content

Commit de8ec9e

Browse files
author
Dominic Tubach
committed
Make VersionBumpCommand compatible with nikolaposa/version 3
Fixes shivas#59.
1 parent 441c0b8 commit de8ec9e

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

Command/VersionBumpCommand.php

+16-9
Original file line numberDiff line numberDiff line change
@@ -71,48 +71,55 @@ protected function execute(InputInterface $input, OutputInterface $output)
7171
$output->writeln(sprintf('Formatter: <comment>%s</comment>', 'Not available'));
7272
}
7373

74+
// Used for BC compatibility with nikolaposa/version 2.2
75+
$isNikolaposaVersion2 = method_exists($version, ['withMajorIncremented']);
76+
7477
$incrementMajor = (int) $input->getOption('major');
7578
if ($incrementMajor > 0) {
7679
for ($i = 0; $i < $incrementMajor; $i++) {
77-
$version = $version->withMajorIncremented();
80+
$version = $isNikolaposaVersion2 ? $version->withMajorIncremented() : $version->incrementMajor();
7881
}
7982
}
8083

8184
$incrementMinor = (int) $input->getOption('minor');
8285
if ($incrementMinor > 0) {
8386
for ($i = 0; $i < $incrementMinor; $i++) {
84-
$version = $version->withMinorIncremented();
87+
$version = $isNikolaposaVersion2 ? $version->withMinorIncremented() : $version->incrementMinor();
8588
}
8689
}
8790

8891
$incrementPatch = (int) $input->getOption('patch');
8992
if ($incrementPatch > 0) {
9093
for ($i = 0; $i < $incrementPatch; $i++) {
91-
$version = $version->withPatchIncremented();
94+
$version = $isNikolaposaVersion2 ? $version->withPatchIncremented() : $version->incrementPatch();
9295
}
9396
}
9497

9598
$preRelease = $input->getOption('prerelease');
9699
if (!empty($preRelease)) {
97-
if (in_array(null, $preRelease)) {
98-
$preRelease = array();
100+
if (in_array(null, $preRelease, true)) {
101+
$preRelease = $isNikolaposaVersion2 ? array() : null;
102+
} else {
103+
$preRelease = implode('.', $preRelease);
99104
}
100105

101106
$version = $version->withPreRelease($preRelease);
102107
}
103108

104109
$build = $input->getOption('build');
105110
if (!empty($build)) {
106-
if (in_array(null, $build)) {
107-
$build = array();
111+
if (in_array(null, $build, true)) {
112+
$build = $isNikolaposaVersion2 ? array() : null;
113+
} else {
114+
$build = implode('.', $build);
108115
}
109116

110117
$version = $version->withBuild($build);
111118
}
112119

113120
$currentVersion = $this->manager->getVersion();
114-
if ((string) $currentVersion == (string) $version) {
115-
$version = $version->withPatchIncremented();
121+
if ((string) $currentVersion === (string) $version) {
122+
$version = $isNikolaposaVersion2 ? $version->withPatchIncremented() : $version->incrementPatch();
116123
}
117124

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

0 commit comments

Comments
 (0)