Chris@14: Chris@14: * Chris@14: * For the full copyright and license information, please view the LICENSE Chris@14: * file that was distributed with this source code. Chris@14: */ Chris@14: Chris@14: namespace SebastianBergmann\CodeCoverage\Report\Xml; Chris@14: Chris@14: class Node Chris@14: { Chris@14: /** Chris@14: * @var \DOMDocument Chris@14: */ Chris@14: private $dom; Chris@14: Chris@14: /** Chris@14: * @var \DOMElement Chris@14: */ Chris@14: private $contextNode; Chris@14: Chris@14: public function __construct(\DOMElement $context) Chris@14: { Chris@14: $this->setContextNode($context); Chris@14: } Chris@14: Chris@14: protected function setContextNode(\DOMElement $context) Chris@14: { Chris@14: $this->dom = $context->ownerDocument; Chris@14: $this->contextNode = $context; Chris@14: } Chris@14: Chris@14: public function getDom() Chris@14: { Chris@14: return $this->dom; Chris@14: } Chris@14: Chris@14: protected function getContextNode() Chris@14: { Chris@14: return $this->contextNode; Chris@14: } Chris@14: Chris@14: public function getTotals() Chris@14: { Chris@14: $totalsContainer = $this->getContextNode()->firstChild; Chris@14: Chris@14: if (!$totalsContainer) { Chris@14: $totalsContainer = $this->getContextNode()->appendChild( Chris@14: $this->dom->createElementNS( Chris@14: 'http://schema.phpunit.de/coverage/1.0', Chris@14: 'totals' Chris@14: ) Chris@14: ); Chris@14: } Chris@14: Chris@14: return new Totals($totalsContainer); Chris@14: } Chris@14: Chris@14: public function addDirectory($name) Chris@14: { Chris@14: $dirNode = $this->getDom()->createElementNS( Chris@14: 'http://schema.phpunit.de/coverage/1.0', Chris@14: 'directory' Chris@14: ); Chris@14: Chris@14: $dirNode->setAttribute('name', $name); Chris@14: $this->getContextNode()->appendChild($dirNode); Chris@14: Chris@14: return new Directory($dirNode); Chris@14: } Chris@14: Chris@14: public function addFile($name, $href) Chris@14: { Chris@14: $fileNode = $this->getDom()->createElementNS( Chris@14: 'http://schema.phpunit.de/coverage/1.0', Chris@14: 'file' Chris@14: ); Chris@14: Chris@14: $fileNode->setAttribute('name', $name); Chris@14: $fileNode->setAttribute('href', $href); Chris@14: $this->getContextNode()->appendChild($fileNode); Chris@14: Chris@14: return new File($fileNode); Chris@14: } Chris@14: }