11<?php
2- class PHP_CodeCoverage_Report_XML {
2+ /**
3+ * PHP_CodeCoverage
4+ *
5+ * Copyright (c) 2009-2013, Sebastian Bergmann <[email protected] >. 6+ * All rights reserved.
7+ *
8+ * Redistribution and use in source and binary forms, with or without
9+ * modification, are permitted provided that the following conditions
10+ * are met:
11+ *
12+ * * Redistributions of source code must retain the above copyright
13+ * notice, this list of conditions and the following disclaimer.
14+ *
15+ * * Redistributions in binary form must reproduce the above copyright
16+ * notice, this list of conditions and the following disclaimer in
17+ * the documentation and/or other materials provided with the
18+ * distribution.
19+ *
20+ * * Neither the name of Sebastian Bergmann nor the names of his
21+ * contributors may be used to endorse or promote products derived
22+ * from this software without specific prior written permission.
23+ *
24+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35+ * POSSIBILITY OF SUCH DAMAGE.
36+ *
37+ * @category PHP
38+ * @package CodeCoverage
39+ * @author Arne Blankerts <[email protected] > 40+ * @copyright 2009-2013 Sebastian Bergmann <[email protected] > 41+ * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
42+ * @link http://github.com/sebastianbergmann/php-code-coverage
43+ * @since File available since Release 1.3.0
44+ */
345
46+ /**
47+ * @category PHP
48+ * @package CodeCoverage
49+ * @author Arne Blankerts <[email protected] > 50+ * @copyright 2009-2013 Sebastian Bergmann <[email protected] > 51+ * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
52+ * @link http://github.com/sebastianbergmann/php-code-coverage
53+ * @since Class available since Release 1.3.0
54+ */
55+ class PHP_CodeCoverage_Report_XML
56+ {
457 /**
558 * @var string
659 */
@@ -16,15 +69,17 @@ public function process(PHP_CodeCoverage $coverage, $target)
1669 if (substr ($ target , -1 , 1 ) != DIRECTORY_SEPARATOR ) {
1770 $ target .= DIRECTORY_SEPARATOR ;
1871 }
72+
1973 $ this ->target = $ target ;
2074 $ this ->initTargetDirectory ($ target );
75+
2176 $ report = $ coverage ->getReport ();
2277
2378 $ this ->project = new PHP_CodeCoverage_Report_XML_Project (
24- $ coverage ->getReport ()->getName ()
79+ $ coverage ->getReport ()->getName ()
2580 );
26- $ this ->processTests ($ coverage ->getTests ());
2781
82+ $ this ->processTests ($ coverage ->getTests ());
2883 $ this ->processDirectory ($ report , $ this ->project );
2984
3085 $ index = $ this ->project ->asDom ();
@@ -36,43 +91,61 @@ public function process(PHP_CodeCoverage $coverage, $target)
3691 private function initTargetDirectory ($ dir )
3792 {
3893 if (file_exists ($ dir )) {
39-
4094 if (!is_dir ($ dir )) {
41- throw new PHP_CodeCoverage_Exception ("' $ dir' exists but is not a directory. " );
95+ throw new PHP_CodeCoverage_Exception (
96+ "' $ dir' exists but is not a directory. "
97+ );
4298 }
4399
44100 if (!is_writable ($ dir )) {
45- throw new PHP_CodeCoverage_Exception ("' $ dir' exists but is not writable. " );
101+ throw new PHP_CodeCoverage_Exception (
102+ "' $ dir' exists but is not writable. "
103+ );
46104 }
47105 }
106+
48107 else if (!@mkdir ($ dir , 0777 , TRUE )) {
49- throw new PHP_CodeCoverage_Exception ("' $ dir' could not be created. " );
108+ throw new PHP_CodeCoverage_Exception (
109+ "' $ dir' could not be created. "
110+ );
50111 }
51112 }
52113
53114 private function processDirectory (PHP_CodeCoverage_Report_Node_Directory $ directory , PHP_CodeCoverage_Report_XML_Node $ context )
54115 {
55116 $ dirObject = $ context ->addDirectory ($ directory ->getName ());
117+
56118 $ this ->setTotals ($ directory , $ dirObject ->getTotals ());
119+
57120 foreach ($ directory as $ node ) {
58121 if ($ node instanceof PHP_CodeCoverage_Report_Node_Directory) {
59122 $ this ->processDirectory ($ node , $ dirObject );
60123 continue ;
61124 }
125+
62126 if ($ node instanceof PHP_CodeCoverage_Report_Node_File) {
63127 $ this ->processFile ($ node , $ dirObject );
64128 continue ;
65129 }
66- throw new PHP_CodeCoverage_Exception ('Unknown node type for XML Report ' );
130+
131+ throw new PHP_CodeCoverage_Exception (
132+ 'Unknown node type for XML report '
133+ );
67134 }
68135 }
69136
70137 private function processFile (PHP_CodeCoverage_Report_Node_File $ file , PHP_CodeCoverage_Report_XML_Directory $ context )
71138 {
72- $ fileObject = $ context ->addFile ($ file ->getName (), $ file ->getId () . '.xml ' );
139+ $ fileObject = $ context ->addFile (
140+ $ file ->getName (), $ file ->getId () . '.xml '
141+ );
142+
73143 $ this ->setTotals ($ file , $ fileObject ->getTotals ());
74144
75- $ fileReport = new PHP_CodeCoverage_Report_XML_File_Report ($ file ->getName ());
145+ $ fileReport = new PHP_CodeCoverage_Report_XML_File_Report (
146+ $ file ->getName ()
147+ );
148+
76149 $ this ->setTotals ($ file , $ fileReport ->getTotals ());
77150
78151 foreach ($ file ->getClassesAndTraits () as $ unit ) {
@@ -87,13 +160,18 @@ private function processFile(PHP_CodeCoverage_Report_Node_File $file, PHP_CodeCo
87160 if (!is_array ($ tests ) || count ($ tests ) == 0 ) {
88161 continue ;
89162 }
163+
90164 $ coverage = $ fileReport ->getLineCoverage ($ line );
165+
91166 foreach ($ tests as $ test ) {
92167 $ coverage ->addTest ($ test );
93168 }
94169 }
95170
96- $ this ->initTargetDirectory ($ this ->target . dirname ($ file ->getId ()) . '/ ' );
171+ $ this ->initTargetDirectory (
172+ $ this ->target . dirname ($ file ->getId ()) . '/ '
173+ );
174+
97175 $ fileDom = $ fileReport ->asDom ();
98176 $ fileDom ->formatOutput = TRUE ;
99177 $ fileDom ->preserveWhiteSpace = FALSE ;
@@ -104,23 +182,23 @@ private function processUnit($unit, PHP_CodeCoverage_Report_XML_File_Report $rep
104182 {
105183 if (isset ($ unit ['className ' ])) {
106184 $ unitObject = $ report ->getClassObject ($ unit ['className ' ]);
107- }
108- else {
185+ } else {
109186 $ unitObject = $ report ->getTraitObject ($ unit ['traitName ' ]);
110187 }
111188
112189 $ unitObject ->setLines (
113- $ unit ['startLine ' ],
114- $ unit ['executableLines ' ],
115- $ unit ['executedLines ' ]
190+ $ unit ['startLine ' ],
191+ $ unit ['executableLines ' ],
192+ $ unit ['executedLines ' ]
116193 );
194+
117195 $ unitObject ->setCrap ($ unit ['crap ' ]);
118196
119197 $ unitObject ->setPackage (
120- $ unit ['package ' ]['fullPackage ' ],
121- $ unit ['package ' ]['package ' ],
122- $ unit ['package ' ]['subpackage ' ],
123- $ unit ['package ' ]['category ' ]
198+ $ unit ['package ' ]['fullPackage ' ],
199+ $ unit ['package ' ]['package ' ],
200+ $ unit ['package ' ]['subpackage ' ],
201+ $ unit ['package ' ]['category ' ]
124202 );
125203
126204 $ unitObject ->setNamespace ($ unit ['package ' ]['namespace ' ]);
@@ -130,13 +208,18 @@ private function processUnit($unit, PHP_CodeCoverage_Report_XML_File_Report $rep
130208 $ methodObject ->setSignature ($ method ['signature ' ]);
131209 $ methodObject ->setLines ($ method ['startLine ' ], $ method ['endLine ' ]);
132210 $ methodObject ->setCrap ($ method ['crap ' ]);
133- $ methodObject ->setTotals ($ method ['executableLines ' ], $ method ['executedLines ' ], $ method ['coverage ' ]);
211+ $ methodObject ->setTotals (
212+ $ method ['executableLines ' ],
213+ $ method ['executedLines ' ],
214+ $ method ['coverage ' ]
215+ );
134216 }
135217 }
136218
137219 private function processFunction ($ function , PHP_CodeCoverage_Report_XML_File_Report $ report )
138220 {
139221 $ functionObject = $ report ->getFunctionObject ($ function ['functionName ' ]);
222+
140223 $ functionObject ->setSignature ($ function ['signature ' ]);
141224 $ functionObject ->setLines ($ function ['startLine ' ]);
142225 $ functionObject ->setCrap ($ function ['crap ' ]);
@@ -146,33 +229,36 @@ private function processFunction($function, PHP_CodeCoverage_Report_XML_File_Rep
146229 private function processTests (array $ tests )
147230 {
148231 $ testsObject = $ this ->project ->getTests ();
232+
149233 foreach ($ tests as $ test => $ result ) {
150234 if ($ test == 'UNCOVERED_FILES_FROM_WHITELIST ' ) {
151235 continue ;
152236 }
237+
153238 $ testsObject ->addTest ($ test , $ result );
154239 }
155240 }
156241
157242 private function setTotals (PHP_CodeCoverage_Report_Node $ node , PHP_CodeCoverage_Report_XML_Totals $ totals )
158243 {
159244 $ loc = $ node ->getLinesOfCode ();
245+
160246 $ totals ->setNumLines (
161- $ loc ['loc ' ],
162- $ loc ['cloc ' ],
163- $ loc ['ncloc ' ],
164- $ node ->getNumExecutableLines (),
165- $ node ->getNumExecutedLines ()
247+ $ loc ['loc ' ],
248+ $ loc ['cloc ' ],
249+ $ loc ['ncloc ' ],
250+ $ node ->getNumExecutableLines (),
251+ $ node ->getNumExecutedLines ()
166252 );
167253
168254 $ totals ->setNumClasses (
169- $ node ->getNumClasses (),
170- $ node ->getNumTestedClasses ()
255+ $ node ->getNumClasses (),
256+ $ node ->getNumTestedClasses ()
171257 );
172258
173259 $ totals ->setNumTraits (
174- $ node ->getNumTraits (),
175- $ node ->getNumTestedTraits ()
260+ $ node ->getNumTraits (),
261+ $ node ->getNumTestedTraits ()
176262 );
177263
178264 $ totals ->setNumMethods (
@@ -181,9 +267,8 @@ private function setTotals(PHP_CodeCoverage_Report_Node $node, PHP_CodeCoverage_
181267 );
182268
183269 $ totals ->setNumFunctions (
184- $ node ->getNumFunctions (),
185- $ node ->getNumTestedFunctions ()
270+ $ node ->getNumFunctions (),
271+ $ node ->getNumTestedFunctions ()
186272 );
187273 }
188-
189- }
274+ }
0 commit comments