1<?php 2/* 3 * This file is part of the php-code-coverage 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 11namespace SebastianBergmann\CodeCoverage\Report\Xml; 12 13class Project extends Node 14{ 15 public function __construct($name) 16 { 17 $this->init(); 18 $this->setProjectName($name); 19 } 20 21 private function init() 22 { 23 $dom = new \DOMDocument; 24 $dom->loadXML('<?xml version="1.0" ?><phpunit xmlns="http://schema.phpunit.de/coverage/1.0"><project/></phpunit>'); 25 26 $this->setContextNode( 27 $dom->getElementsByTagNameNS( 28 'http://schema.phpunit.de/coverage/1.0', 29 'project' 30 )->item(0) 31 ); 32 } 33 34 private function setProjectName($name) 35 { 36 $this->getContextNode()->setAttribute('name', $name); 37 } 38 39 public function getTests() 40 { 41 $testsNode = $this->getContextNode()->getElementsByTagNameNS( 42 'http://schema.phpunit.de/coverage/1.0', 43 'tests' 44 )->item(0); 45 46 if (!$testsNode) { 47 $testsNode = $this->getContextNode()->appendChild( 48 $this->getDom()->createElementNS( 49 'http://schema.phpunit.de/coverage/1.0', 50 'tests' 51 ) 52 ); 53 } 54 55 return new Tests($testsNode); 56 } 57 58 public function asDom() 59 { 60 return $this->getDom(); 61 } 62} 63