Lines
100.00%
18 / 18
Functions and Methods
100.00%
2 / 2
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Version | 100.00% | 18 / 18 | 100.00% | 2 / 2 | 5 | 100.00% | 1 / 1 | |||
| getString | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 3 | |||||
| getArray | 100.00% | 13 / 13 | 100.00% | 1 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | namespace BO\Zmsbackend\Helper; | |
| 4 | ||
| 5 | class Version | |
| 6 | { | |
| 7 | public static function getString($path = null): string | |
| 8 | { | |
| 9 | $path = ($path) ? $path : \App::APP_PATH; | |
| 10 | $file = $path . '/VERSION'; | |
| 11 | if (is_file($file)) { | |
| 12 | return trim(file_get_contents($file)); | |
| 13 | } | |
| 14 | return "version.unknown"; | |
| 15 | } | |
| 16 | ||
| 17 | /** | |
| 18 | * @return string[] | |
| 19 | * | |
| 20 | */ | |
| 21 | public static function getArray($path = null): array | |
| 22 | { | |
| 23 | $version = static::getString($path); | |
| 24 | $array = []; | |
| 25 | if (preg_match('#^(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+.*)$#', $version, $array)) { | |
| 26 | return [ | |
| 27 | 'major' => $array['major'], | |
| 28 | 'minor' => $array['minor'], | |
| 29 | 'patch' => $array['patch'], | |
| 30 | ]; | |
| 31 | } | |
| 32 | return [ | |
| 33 | 'major' => "unknown", | |
| 34 | 'minor' => "0", | |
| 35 | 'patch' => "0", | |
| 36 | ]; | |
| 37 | } | |
| 38 | } |