Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
6 / 6 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
SemanticVersion | |
100.00% |
6 / 6 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
createRandom | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
convert | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
toApplicationVersion | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getRegularExpression | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | namespace Apie\CommonValueObjects; |
3 | |
4 | use Apie\Core\Attributes\FakeMethod; |
5 | use Apie\Core\ValueObjects\Interfaces\HasRegexValueObjectInterface; |
6 | use Apie\Core\ValueObjects\IsStringWithRegexValueObject; |
7 | use Faker\Generator; |
8 | |
9 | #[FakeMethod('createRandom')] |
10 | class SemanticVersion implements HasRegexValueObjectInterface |
11 | { |
12 | use IsStringWithRegexValueObject; |
13 | |
14 | public static function createRandom(Generator $generator): self |
15 | { |
16 | return static::fromNative($generator->semver(true, true)); |
17 | } |
18 | |
19 | protected function convert(string $input): string |
20 | { |
21 | return trim($input); |
22 | } |
23 | |
24 | public function toApplicationVersion(): ApplicationVersion |
25 | { |
26 | preg_match('/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/', $this->internal, $matches); |
27 | assert(!empty($matches)); |
28 | return new ApplicationVersion($matches[1] . '.' . $matches[2] . '.' . $matches[3]); |
29 | } |
30 | |
31 | /** |
32 | * @see https://semver.org/spec/v2.0.0.html |
33 | */ |
34 | public static function getRegularExpression(): string |
35 | { |
36 | return '/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/'; |
37 | } |
38 | } |