Unit.php 2.5 KB

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