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 */ 14class PHP_CodeCoverage_Report_XML_Totals 15{ 16 /** 17 * @var DOMNode 18 */ 19 private $container; 20 21 /** 22 * @var DOMElement 23 */ 24 private $linesNode; 25 26 /** 27 * @var DOMElement 28 */ 29 private $methodsNode; 30 31 /** 32 * @var DOMElement 33 */ 34 private $functionsNode; 35 36 /** 37 * @var DOMElement 38 */ 39 private $classesNode; 40 41 /** 42 * @var DOMElement 43 */ 44 private $traitsNode; 45 46 public function __construct(DOMElement $container) 47 { 48 $this->container = $container; 49 $dom = $container->ownerDocument; 50 51 $this->linesNode = $dom->createElementNS( 52 'http://schema.phpunit.de/coverage/1.0', 53 'lines' 54 ); 55 56 $this->methodsNode = $dom->createElementNS( 57 'http://schema.phpunit.de/coverage/1.0', 58 'methods' 59 ); 60 61 $this->functionsNode = $dom->createElementNS( 62 'http://schema.phpunit.de/coverage/1.0', 63 'functions' 64 ); 65 66 $this->classesNode = $dom->createElementNS( 67 'http://schema.phpunit.de/coverage/1.0', 68 'classes' 69 ); 70 71 $this->traitsNode = $dom->createElementNS( 72 'http://schema.phpunit.de/coverage/1.0', 73 'traits' 74 ); 75 76 $container->appendChild($this->linesNode); 77 $container->appendChild($this->methodsNode); 78 $container->appendChild($this->functionsNode); 79 $container->appendChild($this->classesNode); 80 $container->appendChild($this->traitsNode); 81 } 82 83 public function getContainer() 84 { 85 return $this->container; 86 } 87 88 public function setNumLines($loc, $cloc, $ncloc, $executable, $executed) 89 { 90 $this->linesNode->setAttribute('total', $loc); 91 $this->linesNode->setAttribute('comments', $cloc); 92 $this->linesNode->setAttribute('code', $ncloc); 93 $this->linesNode->setAttribute('executable', $executable); 94 $this->linesNode->setAttribute('executed', $executed); 95 $this->linesNode->setAttribute( 96 'percent', 97 PHP_CodeCoverage_Util::percent($executed, $executable, true) 98 ); 99 } 100 101 public function setNumClasses($count, $tested) 102 { 103 $this->classesNode->setAttribute('count', $count); 104 $this->classesNode->setAttribute('tested', $tested); 105 $this->classesNode->setAttribute( 106 'percent', 107 PHP_CodeCoverage_Util::percent($tested, $count, true) 108 ); 109 } 110 111 public function setNumTraits($count, $tested) 112 { 113 $this->traitsNode->setAttribute('count', $count); 114 $this->traitsNode->setAttribute('tested', $tested); 115 $this->traitsNode->setAttribute( 116 'percent', 117 PHP_CodeCoverage_Util::percent($tested, $count, true) 118 ); 119 } 120 121 public function setNumMethods($count, $tested) 122 { 123 $this->methodsNode->setAttribute('count', $count); 124 $this->methodsNode->setAttribute('tested', $tested); 125 $this->methodsNode->setAttribute( 126 'percent', 127 PHP_CodeCoverage_Util::percent($tested, $count, true) 128 ); 129 } 130 131 public function setNumFunctions($count, $tested) 132 { 133 $this->functionsNode->setAttribute('count', $count); 134 $this->functionsNode->setAttribute('tested', $tested); 135 $this->functionsNode->setAttribute( 136 'percent', 137 PHP_CodeCoverage_Util::percent($tested, $count, true) 138 ); 139 } 140} 141