Skip to content

Commit

Permalink
feature #1 Allow to increment with next (sstok)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.0-dev branch.

Discussion
----------

When the current version is stable increment minor.
For unstable with metaver increment the metaver instead.

Commits
-------

3fc7f09 Allow to increment with next
  • Loading branch information
sstok authored Nov 24, 2017
2 parents c7d3427 + 3fc7f09 commit bfbd7c3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ $version = Version::fromString('v1.3.2');

$newVersion = $version->increase('major'); // v2.0.0
$newVersion = $version->increase('minor'); // v1.4.0
$newVersion = $version->increase('next'); // v1.4.0
$newVersion = $version->increase('patch'); // v1.3.3
$newVersion = $version->increase('stable'); // v1.4.0

Expand All @@ -54,6 +55,7 @@ $version = Version::fromString('v1.4.0-BETA1');
$newVersion = $version->increase('beta'); // v1.4.0-BETA2
$newVersion = $version->increase('rc'); // v1.4.0-RC1
$newVersion = $version->increase('major'); // v1.4.0
$newVersion = $version->increase('next'); // v1.4.0-BETA2
$newVersion = $version->increase('stable'); // v1.4.0

// Version validation
Expand Down
17 changes: 15 additions & 2 deletions src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,15 @@ public function increase(string $stability): Version
case 'stable':
return $this->increaseStable();

case 'next':
return $this->increaseNext();

default:
throw new \InvalidArgumentException(
sprintf(
'Unknown stability "%s", accepts "%s" '.$stability,
implode('", "', ['alpha', 'beta', 'rc', 'stable', 'major', 'minor', 'patch'])
'Unknown stability "%s", accepts "%s".',
$stability,
implode('", "', ['alpha', 'beta', 'rc', 'stable', 'major', 'next', 'minor', 'patch'])
)
);
}
Expand All @@ -233,4 +237,13 @@ private function increaseStable(): Version

return new self($this->major, $this->minor + 1, 0, 3);
}

private function increaseNext(): Version
{
if ($this->major > 0 && $this->stability < 3) {
return new self($this->major, $this->minor, $this->patch, $this->stability, $this->metaver + 1);
}

return new self($this->major, $this->minor + 1, 0, 3);
}
}
7 changes: 7 additions & 0 deletions tests/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ public function provideExpectedIncreasedVersion(): array
'major from 1.0' => ['1.0.0', '2.0.0', 'major'],
'major from 2.0-beta' => ['2.0.0-beta1', '2.0.0', 'major'],

// Next
'new next from 0.1.0' => ['0.1.0', '0.2.0', 'next'],
'new next from 0.1.1' => ['0.1.1', '0.2.0', 'next'],
'new next from alpha' => ['1.0.0-alpha6', '1.0.0-alpha7', 'next'],
'new next from beta' => ['1.0.0-beta1', '1.0.0-beta2', 'next'],
'new next from current stable' => ['1.0.0', '1.1.0', 'next'],

// Alpha
'next alpha' => ['1.0.0-alpha1', '1.0.0-alpha2', 'alpha'],
'new alpha' => ['1.0.0', '1.1.0-alpha1', 'alpha'],
Expand Down

0 comments on commit bfbd7c3

Please sign in to comment.