Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Version
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
2 / 2
5
100.00% covered (success)
100.00%
1 / 1
 getString
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 getArray
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace BO\Zmsbackend\Helper;
4
5class Version
6{
7    public static function getString($path = null)
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    public static function getArray($path = null)
18    {
19        $version = static::getString($path);
20        $array = [];
21        if (preg_match('#^(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+.*)$#', $version, $array)) {
22            return [
23                'major' => $array['major'],
24                'minor' => $array['minor'],
25                'patch' => $array['patch'],
26            ];
27        }
28        return [
29            'major' => "unknown",
30            'minor' => "0",
31            'patch' => "0",
32        ];
33    }
34}