|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of cloak. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Noritaka Horio <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace cloak; |
|
13
|
|
|
|
|
14
|
|
|
use cloak\analyzer\Analyzer; |
|
15
|
|
|
use cloak\analyzer\AnalyzedResult; |
|
16
|
|
|
use cloak\analyzer\result\FileResult; |
|
17
|
|
|
use cloak\analyzer\adapter\XdebugAdapter; |
|
18
|
|
|
use \InvalidArgumentException; |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class AnalyzerConfiguration |
|
23
|
|
|
* @package cloak |
|
24
|
|
|
*/ |
|
25
|
|
|
class AnalyzerConfiguration |
|
26
|
|
|
{ |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var \cloak\analyzer\AnalyzeDriver |
|
30
|
|
|
*/ |
|
31
|
|
|
private $driver; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var \cloak\reporter\Reporter |
|
35
|
|
|
*/ |
|
36
|
|
|
private $reporter; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var string[] |
|
40
|
|
|
*/ |
|
41
|
|
|
private $includeFiles = []; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var string[] |
|
45
|
|
|
*/ |
|
46
|
|
|
private $excludeFiles = []; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var \cloak\value\CoverageBounds |
|
50
|
|
|
*/ |
|
51
|
|
|
private $coverageBounds; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var string |
|
55
|
|
|
*/ |
|
56
|
|
|
private $reportDirectory; |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param array $values |
|
61
|
|
|
*/ |
|
62
|
|
|
public function __construct(array $values = []) |
|
63
|
|
|
{ |
|
64
|
|
|
foreach ($values as $key => $value) { |
|
65
|
|
|
if (property_exists($this, $key) === false) { |
|
66
|
|
|
throw new InvalidArgumentException("Property that does not exist {$key}"); |
|
67
|
|
|
} |
|
68
|
|
|
$this->$key = $value; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return \cloak\analyzer\AnalyzeDriver|null |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getDriver() |
|
76
|
|
|
{ |
|
77
|
|
|
$this->driver = $this->driver ? $this->driver : new Analyzer(new XdebugAdapter()); |
|
78
|
|
|
return $this->driver; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return reporter\Reporter |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getReporter() |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->reporter; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return string[] |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getIncludeFiles() |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->includeFiles; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return string[] |
|
99
|
|
|
*/ |
|
100
|
|
|
public function getExcludeFiles() |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->excludeFiles; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @return value\CoverageBounds |
|
107
|
|
|
*/ |
|
108
|
|
|
public function getCoverageBounds() |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->coverageBounds; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return string |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getReportDirectory() |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->reportDirectory; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @param \cloak\analyzer\AnalyzedResult $result |
|
123
|
|
|
* @return \cloak\analyzer\AnalyzedResult |
|
124
|
|
|
*/ |
|
125
|
|
|
public function applyTo(AnalyzedResult $result) |
|
126
|
|
|
{ |
|
127
|
|
|
$includeCallback = $this->createCallback($this->includeFiles); |
|
128
|
|
|
$excludeCallback = $this->createCallback($this->excludeFiles); |
|
129
|
|
|
|
|
130
|
|
|
return $result->includeFile($includeCallback) |
|
131
|
|
|
->excludeFile($excludeCallback); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @param string[] $patterns |
|
137
|
|
|
* @return callable |
|
138
|
|
|
*/ |
|
139
|
|
|
private function createCallback(array $patterns) |
|
140
|
|
|
{ |
|
141
|
|
|
$filterCallback = function (FileResult $file) use ($patterns) { |
|
142
|
|
|
return $file->matchPaths($patterns); |
|
143
|
|
|
}; |
|
144
|
|
|
|
|
145
|
|
|
return $filterCallback; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
} |
|
149
|
|
|
|