Skip to content

Commit 7bc4704

Browse files
staabmsebastianbergmann
authored andcommitted
Method: Move always available information into __construct()
Reducing the api surface along the way
1 parent 45dff46 commit 7bc4704

File tree

4 files changed

+72
-40
lines changed

4 files changed

+72
-40
lines changed

src/Report/Xml/Facade.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,26 +198,31 @@ private function processUnit(ProcessedClassType|ProcessedTraitType $unit, Report
198198
}
199199

200200
foreach ($unit->methods as $method) {
201-
$methodObject = $unitObject->addMethod($method->methodName);
202-
$methodObject->setSignature($method->signature);
203-
$methodObject->setLines((string) $method->startLine, (string) $method->endLine);
204-
$methodObject->setCrap($method->crap);
205-
$methodObject->setTotals(
201+
$unitObject->addMethod(
202+
$method->methodName,
203+
$method->signature,
204+
(string) $method->startLine,
205+
(string) $method->endLine,
206206
(string) $method->executableLines,
207207
(string) $method->executedLines,
208208
(string) $method->coverage,
209+
$method->crap,
209210
);
210211
}
211212
}
212213

213214
private function processFunction(ProcessedFunctionType $function, Report $report): void
214215
{
215-
$functionObject = $report->functionObject($function->functionName);
216-
217-
$functionObject->setSignature($function->signature);
218-
$functionObject->setLines((string) $function->startLine);
219-
$functionObject->setCrap($function->crap);
220-
$functionObject->setTotals((string) $function->executableLines, (string) $function->executedLines, (string) $function->coverage);
216+
$report->functionObject(
217+
$function->functionName,
218+
$function->signature,
219+
(string) $function->startLine,
220+
null,
221+
(string) $function->executableLines,
222+
(string) $function->executedLines,
223+
(string) $function->coverage,
224+
$function->crap,
225+
);
221226
}
222227

223228
/**

src/Report/Xml/Method.php

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,32 @@
1818
{
1919
private DOMElement $contextNode;
2020

21-
public function __construct(DOMElement $context, string $name)
22-
{
21+
public function __construct(
22+
DOMElement $context,
23+
string $name,
24+
string $signature,
25+
string $start,
26+
?string $end,
27+
string $executable,
28+
string $executed,
29+
string $coverage,
30+
string $crap
31+
) {
2332
$this->contextNode = $context;
2433

25-
$this->setName($name);
26-
}
27-
28-
public function setSignature(string $signature): void
29-
{
34+
$this->contextNode->setAttribute('name', $name);
3035
$this->contextNode->setAttribute('signature', $signature);
31-
}
3236

33-
public function setLines(string $start, ?string $end = null): void
34-
{
3537
$this->contextNode->setAttribute('start', $start);
3638

3739
if ($end !== null) {
3840
$this->contextNode->setAttribute('end', $end);
3941
}
40-
}
4142

42-
public function setTotals(string $executable, string $executed, string $coverage): void
43-
{
43+
$this->contextNode->setAttribute('crap', $crap);
44+
4445
$this->contextNode->setAttribute('executable', $executable);
4546
$this->contextNode->setAttribute('executed', $executed);
4647
$this->contextNode->setAttribute('coverage', $coverage);
4748
}
48-
49-
public function setCrap(string $crap): void
50-
{
51-
$this->contextNode->setAttribute('crap', $crap);
52-
}
53-
54-
private function setName(string $name): void
55-
{
56-
$this->contextNode->setAttribute('name', $name);
57-
}
5849
}

src/Report/Xml/Report.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,16 @@ public function asDom(): DOMDocument
4545
return $this->dom();
4646
}
4747

48-
public function functionObject(string $name): Method
49-
{
48+
public function functionObject(
49+
string $name,
50+
string $signature,
51+
string $start,
52+
?string $end,
53+
string $executable,
54+
string $executed,
55+
string $coverage,
56+
string $crap
57+
): void {
5058
$node = $this->contextNode()->appendChild(
5159
$this->dom()->createElementNS(
5260
Facade::XML_NAMESPACE,
@@ -56,7 +64,17 @@ public function functionObject(string $name): Method
5664

5765
assert($node instanceof DOMElement);
5866

59-
return new Method($node, $name);
67+
new Method(
68+
$node,
69+
$name,
70+
$signature,
71+
$start,
72+
$end,
73+
$executable,
74+
$executed,
75+
$coverage,
76+
$crap,
77+
);
6078
}
6179

6280
public function classObject(

src/Report/Xml/Unit.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,16 @@ public function __construct(
4747
$node->setAttribute('name', $namespace);
4848
}
4949

50-
public function addMethod(string $name): Method
51-
{
50+
public function addMethod(
51+
string $name,
52+
string $signature,
53+
string $start,
54+
?string $end,
55+
string $executable,
56+
string $executed,
57+
string $coverage,
58+
string $crap
59+
): void {
5260
$node = $this->contextNode->appendChild(
5361
$this->contextNode->ownerDocument->createElementNS(
5462
Facade::XML_NAMESPACE,
@@ -58,6 +66,16 @@ public function addMethod(string $name): Method
5866

5967
assert($node instanceof DOMElement);
6068

61-
return new Method($node, $name);
69+
new Method(
70+
$node,
71+
$name,
72+
$signature,
73+
$start,
74+
$end,
75+
$executable,
76+
$executed,
77+
$coverage,
78+
$crap,
79+
);
6280
}
6381
}

0 commit comments

Comments
 (0)