|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace PHPRealCoverage\Parser\Model; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use PHPRealCoverage\Mutator\MutatableLine; |
|
8
|
|
|
use PHPRealCoverage\Proxy\Line; |
|
9
|
|
|
|
|
10
|
|
|
class CoveredLine implements Line, MutatableLine |
|
11
|
|
|
{ |
|
12
|
|
|
private $content; |
|
13
|
|
|
private $method = false; |
|
14
|
|
|
private $final = false; |
|
15
|
|
|
private $methodName; |
|
16
|
|
|
private $neccessary = true; |
|
17
|
|
|
private $coveringTests = array(); |
|
18
|
|
|
private $class = false; |
|
19
|
|
|
private $className; |
|
20
|
|
|
private $executable = false; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct($content) |
|
23
|
|
|
{ |
|
24
|
|
|
$this->content = $content; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @return string |
|
29
|
|
|
*/ |
|
30
|
|
|
public function getContent() |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->content; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @return bool |
|
37
|
|
|
*/ |
|
38
|
|
|
public function isMethod() |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->method; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param boolean $method |
|
45
|
|
|
*/ |
|
46
|
|
|
public function setMethod($method) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->method = $method; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function isFinal() |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->final; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param boolean $final |
|
58
|
|
|
*/ |
|
59
|
|
|
public function setFinal($final) |
|
60
|
|
|
{ |
|
61
|
|
|
$this->final = $final; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function getMethodName() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->methodName; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param string $methodName |
|
71
|
|
|
*/ |
|
72
|
|
|
public function setMethodName($methodName) |
|
73
|
|
|
{ |
|
74
|
|
|
$this->methodName = $methodName; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function __toString() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->getFilteredContent(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function setNeccessary($neccessary) |
|
83
|
|
|
{ |
|
84
|
|
|
$this->neccessary = $neccessary; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function isNeccessary() |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->neccessary; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function getFilteredContent() |
|
93
|
|
|
{ |
|
94
|
|
|
$content = $this->getContent(); |
|
95
|
|
|
if (trim($content) === '<?php') { |
|
96
|
|
|
return ""; |
|
97
|
|
|
} |
|
98
|
|
|
if (!$this->neccessary) { |
|
99
|
|
|
$content = '//' . $content; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
if (!$this->isMethod()) { |
|
103
|
|
|
return $content; |
|
104
|
|
|
} |
|
105
|
|
|
return str_replace('final ', '', $content); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function isClass() |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->class; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @param boolean $isClass |
|
115
|
|
|
*/ |
|
116
|
|
|
public function setClass($isClass) |
|
117
|
|
|
{ |
|
118
|
|
|
$this->class = $isClass; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function getClassName() |
|
122
|
|
|
{ |
|
123
|
|
|
return $this->className; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
public function setClassName($className) |
|
127
|
|
|
{ |
|
128
|
|
|
$this->className = $className; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @param string $test |
|
133
|
|
|
*/ |
|
134
|
|
|
public function addCoverage($test) |
|
135
|
|
|
{ |
|
136
|
|
|
$this->coveringTests[] = $test; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @return bool |
|
141
|
|
|
*/ |
|
142
|
|
|
public function isCovered() |
|
143
|
|
|
{ |
|
144
|
|
|
return !empty($this->coveringTests); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
public function enable() |
|
148
|
|
|
{ |
|
149
|
|
|
$this->setNeccessary(true); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
public function disable() |
|
153
|
|
|
{ |
|
154
|
|
|
$this->setNeccessary(false); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @return bool |
|
159
|
|
|
*/ |
|
160
|
|
|
public function isEnabled() |
|
161
|
|
|
{ |
|
162
|
|
|
return $this->isNeccessary() && $this->isCovered(); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* @param bool $executable |
|
167
|
|
|
*/ |
|
168
|
|
|
public function setExecutable($executable) |
|
169
|
|
|
{ |
|
170
|
|
|
$this->executable = $executable; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* @return bool |
|
175
|
|
|
*/ |
|
176
|
|
|
public function isExecutable() |
|
177
|
|
|
{ |
|
178
|
|
|
return $this->executable; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
public function getCoverage() |
|
182
|
|
|
{ |
|
183
|
|
|
return $this->coveringTests; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
public function isConstructor() |
|
187
|
|
|
{ |
|
188
|
|
|
return $this->isMethod() && strpos($this->getMethodName(), '__construct') === 0; |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|