Chris@14
|
1 <?php
|
Chris@14
|
2 /*
|
Chris@14
|
3 * This file is part of the php-code-coverage package.
|
Chris@14
|
4 *
|
Chris@14
|
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
|
Chris@14
|
6 *
|
Chris@14
|
7 * For the full copyright and license information, please view the LICENSE
|
Chris@14
|
8 * file that was distributed with this source code.
|
Chris@14
|
9 */
|
Chris@14
|
10
|
Chris@14
|
11 namespace SebastianBergmann\CodeCoverage\Report\Xml;
|
Chris@14
|
12
|
Chris@14
|
13 class Report extends File
|
Chris@14
|
14 {
|
Chris@14
|
15 public function __construct($name)
|
Chris@14
|
16 {
|
Chris@14
|
17 $dom = new \DOMDocument();
|
Chris@14
|
18 $dom->loadXML('<?xml version="1.0" ?><phpunit xmlns="http://schema.phpunit.de/coverage/1.0"><file /></phpunit>');
|
Chris@14
|
19
|
Chris@14
|
20 $contextNode = $dom->getElementsByTagNameNS(
|
Chris@14
|
21 'http://schema.phpunit.de/coverage/1.0',
|
Chris@14
|
22 'file'
|
Chris@14
|
23 )->item(0);
|
Chris@14
|
24
|
Chris@14
|
25 parent::__construct($contextNode);
|
Chris@14
|
26 $this->setName($name);
|
Chris@14
|
27 }
|
Chris@14
|
28
|
Chris@14
|
29 private function setName($name)
|
Chris@14
|
30 {
|
Chris@14
|
31 $this->getContextNode()->setAttribute('name', \basename($name));
|
Chris@14
|
32 $this->getContextNode()->setAttribute('path', \dirname($name));
|
Chris@14
|
33 }
|
Chris@14
|
34
|
Chris@14
|
35 public function asDom()
|
Chris@14
|
36 {
|
Chris@14
|
37 return $this->getDomDocument();
|
Chris@14
|
38 }
|
Chris@14
|
39
|
Chris@14
|
40 public function getFunctionObject($name)
|
Chris@14
|
41 {
|
Chris@14
|
42 $node = $this->getContextNode()->appendChild(
|
Chris@14
|
43 $this->getDomDocument()->createElementNS(
|
Chris@14
|
44 'http://schema.phpunit.de/coverage/1.0',
|
Chris@14
|
45 'function'
|
Chris@14
|
46 )
|
Chris@14
|
47 );
|
Chris@14
|
48
|
Chris@14
|
49 return new Method($node, $name);
|
Chris@14
|
50 }
|
Chris@14
|
51
|
Chris@14
|
52 public function getClassObject($name)
|
Chris@14
|
53 {
|
Chris@14
|
54 return $this->getUnitObject('class', $name);
|
Chris@14
|
55 }
|
Chris@14
|
56
|
Chris@14
|
57 public function getTraitObject($name)
|
Chris@14
|
58 {
|
Chris@14
|
59 return $this->getUnitObject('trait', $name);
|
Chris@14
|
60 }
|
Chris@14
|
61
|
Chris@14
|
62 private function getUnitObject($tagName, $name)
|
Chris@14
|
63 {
|
Chris@14
|
64 $node = $this->getContextNode()->appendChild(
|
Chris@14
|
65 $this->getDomDocument()->createElementNS(
|
Chris@14
|
66 'http://schema.phpunit.de/coverage/1.0',
|
Chris@14
|
67 $tagName
|
Chris@14
|
68 )
|
Chris@14
|
69 );
|
Chris@14
|
70
|
Chris@14
|
71 return new Unit($node, $name);
|
Chris@14
|
72 }
|
Chris@14
|
73
|
Chris@14
|
74 public function getSource()
|
Chris@14
|
75 {
|
Chris@14
|
76 $source = $this->getContextNode()->getElementsByTagNameNS(
|
Chris@14
|
77 'http://schema.phpunit.de/coverage/1.0',
|
Chris@14
|
78 'source'
|
Chris@14
|
79 )->item(0);
|
Chris@14
|
80
|
Chris@14
|
81 if (!$source) {
|
Chris@14
|
82 $source = $this->getContextNode()->appendChild(
|
Chris@14
|
83 $this->getDomDocument()->createElementNS(
|
Chris@14
|
84 'http://schema.phpunit.de/coverage/1.0',
|
Chris@14
|
85 'source'
|
Chris@14
|
86 )
|
Chris@14
|
87 );
|
Chris@14
|
88 }
|
Chris@14
|
89
|
Chris@14
|
90 return new Source($source);
|
Chris@14
|
91 }
|
Chris@14
|
92 }
|