diff --git a/src/Report/Xml/BuildInformation.php b/src/Report/Xml/BuildInformation.php index c91e5989e..654eecb31 100644 --- a/src/Report/Xml/BuildInformation.php +++ b/src/Report/Xml/BuildInformation.php @@ -22,13 +22,15 @@ { private DOMElement $contextNode; - public function __construct(DOMElement $contextNode) - { + public function __construct( + DOMElement $contextNode, + Runtime $runtime, + DateTimeImmutable $buildDate, + string $phpUnitVersion, + string $coverageVersion + ) { $this->contextNode = $contextNode; - } - public function setRuntimeInformation(Runtime $runtime): void - { $runtimeNode = $this->nodeByName('runtime'); $runtimeNode->setAttribute('name', $runtime->getName()); @@ -46,34 +48,21 @@ public function setRuntimeInformation(Runtime $runtime): void $driverNode->setAttribute('name', 'pcov'); $driverNode->setAttribute('version', phpversion('pcov')); } - } - public function setBuildTime(DateTimeImmutable $date): void - { - $this->contextNode->setAttribute('time', $date->format('D M j G:i:s T Y')); - } + $this->contextNode->setAttribute('time', $buildDate->format('D M j G:i:s T Y')); - public function setGeneratorVersions(string $phpUnitVersion, string $coverageVersion): void - { $this->contextNode->setAttribute('phpunit', $phpUnitVersion); $this->contextNode->setAttribute('coverage', $coverageVersion); } private function nodeByName(string $name): DOMElement { - $node = $this->contextNode->getElementsByTagNameNS( - Facade::XML_NAMESPACE, - $name, - )->item(0); - - if ($node === null) { - $node = $this->contextNode->appendChild( - $this->contextNode->ownerDocument->createElementNS( - Facade::XML_NAMESPACE, - $name, - ), - ); - } + $node = $this->contextNode->appendChild( + $this->contextNode->ownerDocument->createElementNS( + Facade::XML_NAMESPACE, + $name, + ), + ); assert($node instanceof DOMElement); diff --git a/src/Report/Xml/Facade.php b/src/Report/Xml/Facade.php index 1bc1e009d..857423922 100644 --- a/src/Report/Xml/Facade.php +++ b/src/Report/Xml/Facade.php @@ -79,10 +79,12 @@ public function process(CodeCoverage $coverage, string $target): void private function setBuildInformation(): void { - $buildNode = $this->project->buildInformation(); - $buildNode->setRuntimeInformation(new Runtime); - $buildNode->setBuildTime(new DateTimeImmutable); - $buildNode->setGeneratorVersions($this->phpUnitVersion, Version::id()); + $this->project->buildInformation( + new Runtime, + new DateTimeImmutable, + $this->phpUnitVersion, + Version::id(), + ); } /** diff --git a/src/Report/Xml/Project.php b/src/Report/Xml/Project.php index 160170320..6980a943a 100644 --- a/src/Report/Xml/Project.php +++ b/src/Report/Xml/Project.php @@ -10,8 +10,10 @@ namespace SebastianBergmann\CodeCoverage\Report\Xml; use function assert; +use DateTimeImmutable; use DOMDocument; use DOMElement; +use SebastianBergmann\Environment\Runtime; /** * @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage @@ -40,8 +42,12 @@ public function projectSourceDirectory(): string return $this->directory; } - public function buildInformation(): BuildInformation - { + public function buildInformation( + Runtime $runtime, + DateTimeImmutable $buildDate, + string $phpUnitVersion, + string $coverageVersion + ): void { $buildNode = $this->dom()->getElementsByTagNameNS( Facade::XML_NAMESPACE, 'build', @@ -58,7 +64,13 @@ public function buildInformation(): BuildInformation assert($buildNode instanceof DOMElement); - return new BuildInformation($buildNode); + new BuildInformation( + $buildNode, + $runtime, + $buildDate, + $phpUnitVersion, + $coverageVersion, + ); } public function tests(): Tests