Completed
Push — master ( 8c7411...b8d570 )
by Andrea
10:52
created

FiVersioneController::versione()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 31
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 6.2499

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 12
cts 19
cp 0.6316
rs 8.439
c 0
b 0
f 0
cc 5
eloc 19
nc 5
nop 1
crap 6.2499
1
<?php
2
3
namespace Fi\CoreBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6
use Symfony\Component\Process\Process;
7
8
class FiVersioneController extends Controller
9
{
10
11
    public static $versione;
12
13 10
    public static function versione($container)
14
    {
15
16 10
        if (self::isWindows()) {
17
            return '';
18
        }
19
20 10
        if (self::$versione) {
21
            $risposta = self::$versione;
22
        } else {
23 10
            $projectDir = substr($container->get('kernel')->getRootDir(), 0, -4);
24
25 10
            $cmd = 'cd ' . $projectDir;
26 10
            $process = new Process($cmd . ';git describe --tags');
27 10
            $process->setTimeout(60 * 100);
28 10
            $process->run();
29 10
            if ($process->isSuccessful()) {
30
                $out = explode(chr(10), $process->getOutput());
31
32
                $version = isset($out[0]) ? $out[0] : "0";
33
34
                $risposta = $version;
35
            } else {
36 10
                $risposta = "0";
37
            }
38 10
            self::$versione = $risposta;
39
        }
40
41
42 10
        return $risposta;
43
    }
44
45 10
    public static function isWindows()
46
    {
47 10
        if (PHP_OS == 'WINNT') {
48
            return true;
49
        } else {
50 10
            return false;
51
        }
52
    }
53
}
54