Skip to content

Commit 6fa7c78

Browse files
clxmstaabsebastianbergmann
authored andcommitted
BuildInformation: Move always available information into __construct()
Reducing the api surface along the way
1 parent d8bf935 commit 6fa7c78

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

src/Report/Xml/BuildInformation.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
{
2323
private DOMElement $contextNode;
2424

25-
public function __construct(DOMElement $contextNode)
26-
{
25+
public function __construct(
26+
DOMElement $contextNode,
27+
Runtime $runtime,
28+
DateTimeImmutable $buildDate,
29+
string $phpUnitVersion,
30+
string $coverageVersion
31+
) {
2732
$this->contextNode = $contextNode;
28-
}
2933

30-
public function setRuntimeInformation(Runtime $runtime): void
31-
{
3234
$runtimeNode = $this->nodeByName('runtime');
3335

3436
$runtimeNode->setAttribute('name', $runtime->getName());
@@ -46,15 +48,9 @@ public function setRuntimeInformation(Runtime $runtime): void
4648
$driverNode->setAttribute('name', 'pcov');
4749
$driverNode->setAttribute('version', phpversion('pcov'));
4850
}
49-
}
5051

51-
public function setBuildTime(DateTimeImmutable $date): void
52-
{
53-
$this->contextNode->setAttribute('time', $date->format('D M j G:i:s T Y'));
54-
}
52+
$this->contextNode->setAttribute('time', $buildDate->format('D M j G:i:s T Y'));
5553

56-
public function setGeneratorVersions(string $phpUnitVersion, string $coverageVersion): void
57-
{
5854
$this->contextNode->setAttribute('phpunit', $phpUnitVersion);
5955
$this->contextNode->setAttribute('coverage', $coverageVersion);
6056
}

src/Report/Xml/Facade.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@ public function process(CodeCoverage $coverage, string $target): void
7979

8080
private function setBuildInformation(): void
8181
{
82-
$buildNode = $this->project->buildInformation();
83-
$buildNode->setRuntimeInformation(new Runtime);
84-
$buildNode->setBuildTime(new DateTimeImmutable);
85-
$buildNode->setGeneratorVersions($this->phpUnitVersion, Version::id());
82+
$this->project->buildInformation(
83+
new Runtime,
84+
new DateTimeImmutable,
85+
$this->phpUnitVersion,
86+
Version::id(),
87+
);
8688
}
8789

8890
/**

src/Report/Xml/Project.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
namespace SebastianBergmann\CodeCoverage\Report\Xml;
1111

1212
use function assert;
13+
use DateTimeImmutable;
1314
use DOMDocument;
1415
use DOMElement;
16+
use SebastianBergmann\Environment\Runtime;
1517

1618
/**
1719
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
@@ -40,8 +42,12 @@ public function projectSourceDirectory(): string
4042
return $this->directory;
4143
}
4244

43-
public function buildInformation(): BuildInformation
44-
{
45+
public function buildInformation(
46+
Runtime $runtime,
47+
DateTimeImmutable $buildDate,
48+
string $phpUnitVersion,
49+
string $coverageVersion
50+
): void {
4551
$buildNode = $this->dom()->getElementsByTagNameNS(
4652
Facade::XML_NAMESPACE,
4753
'build',
@@ -58,7 +64,13 @@ public function buildInformation(): BuildInformation
5864

5965
assert($buildNode instanceof DOMElement);
6066

61-
return new BuildInformation($buildNode);
67+
new BuildInformation(
68+
$buildNode,
69+
$runtime,
70+
$buildDate,
71+
$phpUnitVersion,
72+
$coverageVersion,
73+
);
6274
}
6375

6476
public function tests(): Tests

0 commit comments

Comments
 (0)