Completed
Pull Request — master (#266)
by Enrico
10:12
created

Application::getStringVersion()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 9
ccs 4
cts 5
cp 0.8
crap 2.032
rs 9.6666
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA;
7
8
class Application extends \Symfony\Component\Console\Application
9
{
10
    /**
11
     * @var Configuration
12
     */
13
    public $configuration;
14
15
    /**
16
     * @var IssuesCollector
17
     */
18
    protected $issuesCollector;
19
20
    /**
21
     * @var Compiler
22
     */
23
    public $compiler;
24
25
    const VERSION = '0.6.1';
26
27
    /**
28
     * Starts the application.
29
     */
30 872
    public function __construct()
31
    {
32 872
        parent::__construct('PHP Smart Analyzer', $this->getStringVersion());
33
34 872
        $this->add(new Command\CheckCommand());
35 872
        $this->add(new Command\CompileCommand());
36 872
        $this->add(new Command\DumpReferenceCommand());
37 872
        $this->add(new Command\DumpDocumentationCommand());
38
39 872
        $this->issuesCollector = new IssuesCollector();
40 872
        $this->configuration = new Configuration();
41 872
    }
42
43
    /**
44
     * Returns the version as a string.
45
     *
46
     * @return string
47
     */
48 872
    protected function getStringVersion()
49
    {
50 872
        $hash = $this->getCVVersion();
51 872
        if (!empty($hash)) {
52 872
            return self::VERSION . ' #' . $hash;
53
        }
54
55
        return self::VERSION;
56
    }
57
58
    /**
59
     * Returns CV Version.
60
     *
61
     * @return string
62
     */
63 872
    protected function getCVVersion()
64
    {
65 872
        exec('git describe --always', $version_mini_hash);
66
67 872
        return $version_mini_hash ? $version_mini_hash[0] : '';
68
    }
69
70
    /**
71
     * Get the configuration object.
72
     *
73
     * @return Configuration
74
     */
75 46
    public function getConfiguration()
76
    {
77 46
        return $this->configuration;
78
    }
79
80
    /**
81
     * Get the IssuesCollector object.
82
     *
83
     * @return IssuesCollector
84
     */
85 46
    public function getIssuesCollector()
86
    {
87 46
        return $this->issuesCollector;
88
    }
89
}
90