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

FiVersioneController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 65.22%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 46
ccs 15
cts 23
cp 0.6522
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B versione() 0 31 5
A isWindows() 0 8 2
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