Completed
Push — master ( af006f...5a2620 )
by Дмитрий
03:11
created

Application::getIssuesCollector()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA;
7
8
/**
9
 * PHPSA Application
10
 */
11
class Application extends \Symfony\Component\Console\Application
12
{
13
    /**
14
     * @var Configuration
15
     */
16
    public $configuration;
17
18
    /**
19
     * @var IssuesCollector
20
     */
21
    protected $issuesCollector;
22
23
    /**
24
     * @var Compiler
25
     */
26
    public $compiler;
27
28
    const VERSION = '0.6.2';
29
30
    /**
31
     * Starts the application.
32
     */
33 887
    public function __construct()
34
    {
35 887
        parent::__construct('PHP Smart Analyzer', $this->getStringVersion());
36
37 887
        $this->add(new Command\CheckCommand());
38 887
        $this->add(new Command\CompileCommand());
39 887
        $this->add(new Command\DumpReferenceCommand());
40 887
        $this->add(new Command\DumpDocumentationCommand());
41
42 887
        $this->issuesCollector = new IssuesCollector();
43 887
        $this->configuration = new Configuration();
44 887
    }
45
46
    /**
47
     * Returns the version as a string.
48
     *
49
     * @return string
50
     * @codeCoverageIgnore
51
     */
52
    protected function getStringVersion()
53
    {
54
        $hash = $this->getCVVersion();
55
        if ($hash) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $hash of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
56
            return self::VERSION . ' #' . $hash;
57
        }
58
59
        return self::VERSION;
60
    }
61
62
    /**
63
     * Returns CV Version.
64
     *
65
     * @return string|null
66
     * @codeCoverageIgnore
67
     */
68
    protected function getCVVersion()
69
    {
70
        if (!extension_loaded('pcntl')) {
71
            return null;
72
        }
73
74
        $proc = proc_open(
75
            'git describe --always',
76
            [
77
                1 => ['pipe','w'],
78
            ],
79
            $pipes
80
        );
81
        if ($proc) {
82
            $stdout = stream_get_contents($pipes[1]);
83
            fclose($pipes[1]);
84
85
            $exitCode = proc_close($proc);
86
            if ($exitCode === 0) {
87
                return $stdout;
88
            }
89
        }
90
91
        return null;
92
    }
93
94
    /**
95
     * Get the configuration object.
96
     *
97
     * @return Configuration
98
     */
99 51
    public function getConfiguration()
100
    {
101 51
        return $this->configuration;
102
    }
103
104
    /**
105
     * Get the IssuesCollector object.
106
     *
107
     * @return IssuesCollector
108
     */
109 51
    public function getIssuesCollector()
110
    {
111 51
        return $this->issuesCollector;
112
    }
113
}
114