comparison vendor/phpunit/php-code-coverage/src/CodeCoverage/Report/XML/Node.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2 /*
3 * This file is part of the PHP_CodeCoverage package.
4 *
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 /**
12 * @since Class available since Release 2.0.0
13 */
14 class PHP_CodeCoverage_Report_XML_Node
15 {
16 /**
17 * @var DOMDocument
18 */
19 private $dom;
20
21 /**
22 * @var DOMElement
23 */
24 private $contextNode;
25
26 public function __construct(DOMElement $context)
27 {
28 $this->setContextNode($context);
29 }
30
31 protected function setContextNode(DOMElement $context)
32 {
33 $this->dom = $context->ownerDocument;
34 $this->contextNode = $context;
35 }
36
37 public function getDom()
38 {
39 return $this->dom;
40 }
41
42 protected function getContextNode()
43 {
44 return $this->contextNode;
45 }
46
47 public function getTotals()
48 {
49 $totalsContainer = $this->getContextNode()->firstChild;
50
51 if (!$totalsContainer) {
52 $totalsContainer = $this->getContextNode()->appendChild(
53 $this->dom->createElementNS(
54 'http://schema.phpunit.de/coverage/1.0',
55 'totals'
56 )
57 );
58 }
59
60 return new PHP_CodeCoverage_Report_XML_Totals($totalsContainer);
61 }
62
63 public function addDirectory($name)
64 {
65 $dirNode = $this->getDom()->createElementNS(
66 'http://schema.phpunit.de/coverage/1.0',
67 'directory'
68 );
69
70 $dirNode->setAttribute('name', $name);
71 $this->getContextNode()->appendChild($dirNode);
72
73 return new PHP_CodeCoverage_Report_XML_Directory($dirNode);
74 }
75
76 public function addFile($name, $href)
77 {
78 $fileNode = $this->getDom()->createElementNS(
79 'http://schema.phpunit.de/coverage/1.0',
80 'file'
81 );
82
83 $fileNode->setAttribute('name', $name);
84 $fileNode->setAttribute('href', $href);
85 $this->getContextNode()->appendChild($fileNode);
86
87 return new PHP_CodeCoverage_Report_XML_File($fileNode);
88 }
89 }