Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| ApplicationVersion | |
100.00% |
11 / 11 |
|
100.00% |
6 / 6 |
8 | |
100.00% |
1 / 1 |
| convert | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRegularExpression | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| bumpPatch | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| bumpMinor | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| bumpMajor | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| toSemanticVersion | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | namespace Apie\CommonValueObjects; |
| 3 | |
| 4 | use Apie\Core\Attributes\Description; |
| 5 | use Apie\Core\ValueObjects\Interfaces\HasRegexValueObjectInterface; |
| 6 | use Apie\Core\ValueObjects\IsStringWithRegexValueObject; |
| 7 | |
| 8 | #[Description('A semantic version without any suffix, for example "1.0.0"')] |
| 9 | class ApplicationVersion implements HasRegexValueObjectInterface |
| 10 | { |
| 11 | use IsStringWithRegexValueObject; |
| 12 | |
| 13 | protected function convert(string $input): string |
| 14 | { |
| 15 | return trim($input); |
| 16 | } |
| 17 | |
| 18 | public static function getRegularExpression(): string |
| 19 | { |
| 20 | return '/^[1-9]*[0-9]\.[1-9]*[0-9]\.[1-9]*[0-9]$/'; |
| 21 | } |
| 22 | |
| 23 | public function bumpPatch(): self |
| 24 | { |
| 25 | [$major, $minor, $patch] = explode('.', $this->internal); |
| 26 | |
| 27 | return new self(sprintf('%d.%d.%d', $major, $minor, (int) $patch + 1)); |
| 28 | } |
| 29 | |
| 30 | public function bumpMinor(): self |
| 31 | { |
| 32 | [$major, $minor] = explode('.', $this->internal); |
| 33 | |
| 34 | return new self(sprintf('%d.%d.%d', $major, (int) $minor + 1, 0)); |
| 35 | } |
| 36 | |
| 37 | public function bumpMajor(): self |
| 38 | { |
| 39 | [$major] = explode('.', $this->internal, 2); |
| 40 | |
| 41 | return new self(sprintf('%d.%d.%d', (int) $major + 1, 0, 0)); |
| 42 | } |
| 43 | |
| 44 | public function toSemanticVersion(string $suffix = ''): SemanticVersion |
| 45 | { |
| 46 | if ($suffix && false !== strpos('0123456789', substr($suffix, 0, 1))) { |
| 47 | throw new \LogicException('Suffix can not start with a digit!'); |
| 48 | } |
| 49 | return new SemanticVersion($this->internal . $suffix); |
| 50 | } |
| 51 | } |