Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
78.57% covered (warning)
78.57%
11 / 14
33.33% covered (danger)
33.33%
1 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
Git
78.57% covered (warning)
78.57%
11 / 14
33.33% covered (danger)
33.33%
1 / 3
5.25
0.00% covered (danger)
0.00%
0 / 1
 readCurrentHead
66.67% covered (warning)
66.67%
4 / 6
0.00% covered (danger)
0.00%
0 / 1
2.15
 readCurrentHash
80.00% covered (warning)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
2.03
 readCurrentVersion
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
5 **/
6
7namespace BO\Slim;
8
9/**
10  * Helper for GIT integration
11  *
12  */
13class Git
14{
15    public static function readCurrentHead()
16    {
17        $headString = "no version control";
18        $githead = \App::APP_PATH . '/.git/HEAD';
19        if (is_readable($githead)) {
20            $headString = trim(fgets(fopen($githead, 'r')));
21            $headString = preg_replace('#^.* ([^\s]+)$#', '$1', $headString);
22        }
23        return $headString;
24    }
25
26    public static function readCurrentHash()
27    {
28        $headString = static::readCurrentHead();
29        $githashFile = \App::APP_PATH . '/.git/' . $headString;
30        if (is_readable($githashFile)) {
31            return trim(fgets(fopen($githashFile, 'r')));
32        }
33
34        return $headString;
35    }
36
37    public static function readCurrentVersion()
38    {
39        $headString = static::readCurrentHead();
40        $headString = preg_replace('#refs/heads/#', '', $headString);
41        return $headString;
42    }
43}