| Conditions | 4 |
| Paths | 5 |
| Total Lines | 24 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 25 | * @return array |
||
| 26 | */ |
||
| 27 | 10 | public static function parse($versionStr) |
|
| 28 | { |
||
| 29 | 10 | if (!static::validateVersion($versionStr)) { |
|
| 30 | 1 | throw new InvalidVersionException("Invalid version string: {$versionStr}"); |
|
| 31 | } |
||
| 32 | |||
| 33 | 9 | $buildMetadata = []; |
|
| 34 | 9 | $preRelease = []; |
|
| 35 | |||
| 36 | 9 | if (false !== strpos($versionStr, '+')) { |
|
| 37 | 4 | list($versionStr, $buildMetadata) = explode('+', $versionStr); |
|
| 38 | 4 | $buildMetadata = explode('.', $buildMetadata); |
|
| 39 | 4 | } |
|
| 40 | |||
| 41 | 9 | if (false !== ($pos = strpos($versionStr, '-'))) { |
|
| 42 | 8 | $original = $versionStr; |
|
| 43 | 8 | $versionStr = substr($versionStr, 0, $pos); |
|
| 44 | 8 | $preRelease = explode('.', substr($original, $pos + 1)); |
|
| 45 | 8 | } |
|
| 46 | |||
| 47 | 9 | list($major, $minor, $patch) = array_map('intval', explode('.', $versionStr)); |
|
| 48 | |||
| 49 | 9 | return compact('major', 'minor', 'patch', 'preRelease', 'buildMetadata'); |
|
| 52 |