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 Unit 14{ 15 /** 16 * @var \DOMElement 17 */ 18 private $contextNode; 19 20 public function __construct(\DOMElement $context, $name) 21 { 22 $this->contextNode = $context; 23 24 $this->setName($name); 25 } 26 27 private function setName($name) 28 { 29 $this->contextNode->setAttribute('name', $name); 30 } 31 32 public function setLines($start, $executable, $executed) 33 { 34 $this->contextNode->setAttribute('start', $start); 35 $this->contextNode->setAttribute('executable', $executable); 36 $this->contextNode->setAttribute('executed', $executed); 37 } 38 39 public function setCrap($crap) 40 { 41 $this->contextNode->setAttribute('crap', $crap); 42 } 43 44 public function setPackage($full, $package, $sub, $category) 45 { 46 $node = $this->contextNode->getElementsByTagNameNS( 47 'http://schema.phpunit.de/coverage/1.0', 48 'package' 49 )->item(0); 50 51 if (!$node) { 52 $node = $this->contextNode->appendChild( 53 $this->contextNode->ownerDocument->createElementNS( 54 'http://schema.phpunit.de/coverage/1.0', 55 'package' 56 ) 57 ); 58 } 59 60 $node->setAttribute('full', $full); 61 $node->setAttribute('name', $package); 62 $node->setAttribute('sub', $sub); 63 $node->setAttribute('category', $category); 64 } 65 66 public function setNamespace($namespace) 67 { 68 $node = $this->contextNode->getElementsByTagNameNS( 69 'http://schema.phpunit.de/coverage/1.0', 70 'namespace' 71 )->item(0); 72 73 if (!$node) { 74 $node = $this->contextNode->appendChild( 75 $this->contextNode->ownerDocument->createElementNS( 76 'http://schema.phpunit.de/coverage/1.0', 77 'namespace' 78 ) 79 ); 80 } 81 82 $node->setAttribute('name', $namespace); 83 } 84 85 public function addMethod($name) 86 { 87 $node = $this->contextNode->appendChild( 88 $this->contextNode->ownerDocument->createElementNS( 89 'http://schema.phpunit.de/coverage/1.0', 90 'method' 91 ) 92 ); 93 94 return new Method($node, $name); 95 } 96} 97