Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
Version | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getVersion | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
5 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Engelsystem\Helpers; |
6 | |
7 | use Engelsystem\Config\Config; |
8 | use Illuminate\Support\Str; |
9 | |
10 | class Version |
11 | { |
12 | public function __construct(protected string $gitRoot, protected string $storage, protected Config $config) |
13 | { |
14 | } |
15 | |
16 | public function getVersion(): string |
17 | { |
18 | $file = $this->storage . DIRECTORY_SEPARATOR . 'VERSION'; |
19 | $gitHead = implode(DIRECTORY_SEPARATOR, [$this->gitRoot, 'logs', 'HEAD']); |
20 | |
21 | $version = 'n/a'; |
22 | if (file_exists($file)) { |
23 | $version = trim(file_get_contents($file)); |
24 | } elseif (file_exists($gitHead)) { |
25 | $lines = file($gitHead) ?: []; |
26 | $lastLine = array_pop($lines) ?: ''; |
27 | $words = explode(' ', $lastLine); |
28 | $version = Str::substr($words[1] ?? '', 0, 7); |
29 | } |
30 | |
31 | return $this->config->get('version', $version); |
32 | } |
33 | } |