1 | <?php |
||
9 | class Writer |
||
10 | { |
||
11 | /** |
||
12 | * The name attribute of the testsuite being |
||
13 | * written. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $name; |
||
18 | |||
19 | /** |
||
20 | * @var \ParaTest\Logging\LogInterpreter |
||
21 | */ |
||
22 | protected $interpreter; |
||
23 | |||
24 | /** |
||
25 | * @var \DOMDocument |
||
26 | */ |
||
27 | protected $document; |
||
28 | |||
29 | /** |
||
30 | * A pattern for matching testsuite attributes. |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | protected static $suiteAttrs = '/name|(?:test|assertion|failure|error)s|time|file/'; |
||
35 | |||
36 | /** |
||
37 | * A pattern for matching testcase attrs. |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | protected static $caseAttrs = '/name|class|file|line|assertions|time/'; |
||
42 | |||
43 | /** |
||
44 | * A default suite to ease flattening of |
||
45 | * suite structures. |
||
46 | * |
||
47 | * @var array |
||
48 | */ |
||
49 | protected static $defaultSuite = [ |
||
50 | 'tests' => 0, |
||
51 | 'assertions' => 0, |
||
52 | 'failures' => 0, |
||
53 | 'skipped' => 0, |
||
54 | 'errors' => 0, |
||
55 | 'time' => 0, |
||
56 | ]; |
||
57 | |||
58 | 7 | public function __construct(LogInterpreter $interpreter, string $name = '') |
|
65 | |||
66 | /** |
||
67 | * Get the name of the root suite being written. |
||
68 | * |
||
69 | * @return string |
||
70 | */ |
||
71 | 1 | public function getName(): string |
|
75 | |||
76 | /** |
||
77 | * Returns the xml structure the writer |
||
78 | * will use. |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | 6 | public function getXml(): string |
|
95 | |||
96 | /** |
||
97 | * Write the xml structure to a file path. |
||
98 | * |
||
99 | * @param $path |
||
100 | */ |
||
101 | 2 | public function write(string $path) |
|
105 | |||
106 | /** |
||
107 | * Append a testsuite node to the given |
||
108 | * root element. |
||
109 | * |
||
110 | * @param $root |
||
111 | * @param TestSuite $suite |
||
112 | * |
||
113 | * @return \DOMElement |
||
114 | */ |
||
115 | 6 | protected function appendSuite(\DOMElement $root, TestSuite $suite): \DOMElement |
|
128 | |||
129 | /** |
||
130 | * Append a testcase node to the given testsuite |
||
131 | * node. |
||
132 | * |
||
133 | * @param $suiteNode |
||
134 | * @param TestCase $case |
||
135 | * |
||
136 | * @return \DOMElement |
||
137 | */ |
||
138 | 6 | protected function appendCase(\DOMElement $suiteNode, TestCase $case): \DOMElement |
|
156 | |||
157 | /** |
||
158 | * Append error or failure nodes to the given testcase node. |
||
159 | * |
||
160 | * @param $caseNode |
||
161 | * @param $defects |
||
162 | * @param $type |
||
163 | */ |
||
164 | 6 | protected function appendDefects(\DOMElement $caseNode, array $defects, string $type) |
|
172 | |||
173 | /** |
||
174 | * Get the root level testsuite node. |
||
175 | * |
||
176 | * @param $suites |
||
177 | * |
||
178 | * @return \DOMElement |
||
179 | */ |
||
180 | 6 | protected function getSuiteRoot(array $suites): \DOMElement |
|
196 | |||
197 | /** |
||
198 | * Get the attributes used on the root testsuite |
||
199 | * node. |
||
200 | * |
||
201 | * @param $suites |
||
202 | * |
||
203 | * @return mixed |
||
204 | */ |
||
205 | protected function getSuiteRootAttributes(array $suites) |
||
218 | |||
219 | /** |
||
220 | * Prevent writing empty "line" XML attributes which could break parsers. |
||
221 | * |
||
222 | * @param string $name |
||
223 | * @param mixed $value |
||
224 | * |
||
225 | * @return bool |
||
226 | */ |
||
227 | 6 | private function isEmptyLineAttribute(string $name, $value): bool |
|
231 | } |
||
232 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.