|
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
|
1 |
|
public function __construct() |
|
34
|
|
|
{ |
|
35
|
1 |
|
parent::__construct('PHP Smart Analyzer', $this->getStringVersion()); |
|
36
|
|
|
|
|
37
|
1 |
|
$this->add(new Command\CheckCommand()); |
|
38
|
1 |
|
$this->add(new Command\CompileCommand()); |
|
39
|
1 |
|
$this->add(new Command\PrintCFGCommand()); |
|
40
|
1 |
|
$this->add(new Command\DumpReferenceCommand()); |
|
41
|
1 |
|
$this->add(new Command\DumpDocumentationCommand()); |
|
42
|
|
|
|
|
43
|
1 |
|
$this->issuesCollector = new IssuesCollector(); |
|
44
|
1 |
|
$this->configuration = new Configuration(); |
|
45
|
1 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Returns the version as a string. |
|
49
|
|
|
* |
|
50
|
|
|
* @return string |
|
51
|
|
|
* @codeCoverageIgnore |
|
52
|
|
|
*/ |
|
53
|
|
|
protected function getStringVersion() |
|
54
|
|
|
{ |
|
55
|
|
|
$hash = $this->getCVVersion(); |
|
56
|
|
|
if ($hash) { |
|
|
|
|
|
|
57
|
|
|
return self::VERSION . ' #' . $hash; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return self::VERSION; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Returns CV Version. |
|
65
|
|
|
* |
|
66
|
|
|
* @return string|null |
|
67
|
|
|
* @codeCoverageIgnore |
|
68
|
|
|
*/ |
|
69
|
|
|
protected function getCVVersion() |
|
70
|
|
|
{ |
|
71
|
|
|
if (!extension_loaded('pcntl')) { |
|
72
|
|
|
return null; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
$proc = proc_open( |
|
76
|
|
|
'git describe --always', |
|
77
|
|
|
[ |
|
78
|
|
|
// STDOUT |
|
79
|
|
|
1 => ['pipe','w'], |
|
80
|
|
|
// STDERR |
|
81
|
|
|
2 => ['pipe','w'] |
|
82
|
|
|
], |
|
83
|
|
|
$pipes |
|
84
|
|
|
); |
|
85
|
|
|
if ($proc) { |
|
86
|
|
|
$stdout = stream_get_contents($pipes[1]); |
|
87
|
|
|
|
|
88
|
|
|
fclose($pipes[1]); |
|
89
|
|
|
fclose($pipes[2]); |
|
90
|
|
|
|
|
91
|
|
|
$exitCode = proc_close($proc); |
|
92
|
|
|
if ($exitCode === 0) { |
|
93
|
|
|
return $stdout; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
return null; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Get the configuration object. |
|
102
|
|
|
* |
|
103
|
|
|
* @return Configuration |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getConfiguration() |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->configuration; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Get the IssuesCollector object. |
|
112
|
|
|
* |
|
113
|
|
|
* @return IssuesCollector |
|
114
|
|
|
*/ |
|
115
|
1 |
|
public function getIssuesCollector() |
|
116
|
|
|
{ |
|
117
|
1 |
|
return $this->issuesCollector; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: