Lines
16.66%
3 / 18
Methods
0.00%
0 / 2
Classes
0.00%
0 / 1
| 5 | class Version | |
| 6 | { | |
| 7 | const string UNKNOWN = 'version.unknown'; | |
| 8 | ||
| 9 | public static function getString(): string | |
| 10 | { | |
| 11 | $file = \App::APP_PATH . '/VERSION'; | |
| 12 | if (is_file($file)) { | |
| 13 | $contents = file_get_contents($file); | |
| 14 | return is_string($contents) ? trim($contents) : static::UNKNOWN; | |
| 15 | } | |
| 16 | return static::UNKNOWN; | |
| 17 | } | |
| 18 | ||
| 19 | /** | |
| 20 | * @return string[] | |
| 21 | * @psalm-api | |
| 22 | */ | |
| 23 | public static function getArray(): array | |
| 24 | { | |
| 25 | $version = static::getString(); | |
| 26 | $array = []; | |
| 27 | if (preg_match('#^v(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)$#', $version, $array)) { | |
| 28 | return [ | |
| 29 | 'major' => $array['major'], | |
| 30 | 'minor' => $array['minor'], | |
| 31 | 'patch' => $array['patch'], | |
| 32 | ]; | |
| 33 | } | |
| 34 | return [ | |
| 35 | 'major' => "unknown", | |
| 36 | 'minor' => "0", | |
| 37 | 'patch' => "0", | |
| 38 | ]; | |
| 39 | } | |
| 40 | } |