From ec1d25d448d4d9c9710f2bc5a8dc692e9ee9240a Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 20 Nov 2025 09:14:18 +0100 Subject: [PATCH] Method: Move always available information into __construct() Reducing the api surface along the way --- src/Report/Xml/Facade.php | 27 ++++++++++++++++----------- src/Report/Xml/Method.php | 37 ++++++++++++++----------------------- src/Report/Xml/Report.php | 24 +++++++++++++++++++++--- src/Report/Xml/Unit.php | 24 +++++++++++++++++++++--- 4 files changed, 72 insertions(+), 40 deletions(-) diff --git a/src/Report/Xml/Facade.php b/src/Report/Xml/Facade.php index b2982e859..1bc1e009d 100644 --- a/src/Report/Xml/Facade.php +++ b/src/Report/Xml/Facade.php @@ -198,26 +198,31 @@ private function processUnit(ProcessedClassType|ProcessedTraitType $unit, Report } foreach ($unit->methods as $method) { - $methodObject = $unitObject->addMethod($method->methodName); - $methodObject->setSignature($method->signature); - $methodObject->setLines((string) $method->startLine, (string) $method->endLine); - $methodObject->setCrap($method->crap); - $methodObject->setTotals( + $unitObject->addMethod( + $method->methodName, + $method->signature, + (string) $method->startLine, + (string) $method->endLine, (string) $method->executableLines, (string) $method->executedLines, (string) $method->coverage, + $method->crap, ); } } private function processFunction(ProcessedFunctionType $function, Report $report): void { - $functionObject = $report->functionObject($function->functionName); - - $functionObject->setSignature($function->signature); - $functionObject->setLines((string) $function->startLine); - $functionObject->setCrap($function->crap); - $functionObject->setTotals((string) $function->executableLines, (string) $function->executedLines, (string) $function->coverage); + $report->functionObject( + $function->functionName, + $function->signature, + (string) $function->startLine, + null, + (string) $function->executableLines, + (string) $function->executedLines, + (string) $function->coverage, + $function->crap, + ); } /** diff --git a/src/Report/Xml/Method.php b/src/Report/Xml/Method.php index 1994d0f79..1b5bdb28f 100644 --- a/src/Report/Xml/Method.php +++ b/src/Report/Xml/Method.php @@ -18,41 +18,32 @@ { private DOMElement $contextNode; - public function __construct(DOMElement $context, string $name) - { + public function __construct( + DOMElement $context, + string $name, + string $signature, + string $start, + ?string $end, + string $executable, + string $executed, + string $coverage, + string $crap + ) { $this->contextNode = $context; - $this->setName($name); - } - - public function setSignature(string $signature): void - { + $this->contextNode->setAttribute('name', $name); $this->contextNode->setAttribute('signature', $signature); - } - public function setLines(string $start, ?string $end = null): void - { $this->contextNode->setAttribute('start', $start); if ($end !== null) { $this->contextNode->setAttribute('end', $end); } - } - public function setTotals(string $executable, string $executed, string $coverage): void - { + $this->contextNode->setAttribute('crap', $crap); + $this->contextNode->setAttribute('executable', $executable); $this->contextNode->setAttribute('executed', $executed); $this->contextNode->setAttribute('coverage', $coverage); } - - public function setCrap(string $crap): void - { - $this->contextNode->setAttribute('crap', $crap); - } - - private function setName(string $name): void - { - $this->contextNode->setAttribute('name', $name); - } } diff --git a/src/Report/Xml/Report.php b/src/Report/Xml/Report.php index 601e466c3..14d2d5a06 100644 --- a/src/Report/Xml/Report.php +++ b/src/Report/Xml/Report.php @@ -45,8 +45,16 @@ public function asDom(): DOMDocument return $this->dom(); } - public function functionObject(string $name): Method - { + public function functionObject( + string $name, + string $signature, + string $start, + ?string $end, + string $executable, + string $executed, + string $coverage, + string $crap + ): void { $node = $this->contextNode()->appendChild( $this->dom()->createElementNS( Facade::XML_NAMESPACE, @@ -56,7 +64,17 @@ public function functionObject(string $name): Method assert($node instanceof DOMElement); - return new Method($node, $name); + new Method( + $node, + $name, + $signature, + $start, + $end, + $executable, + $executed, + $coverage, + $crap, + ); } public function classObject( diff --git a/src/Report/Xml/Unit.php b/src/Report/Xml/Unit.php index 35175f30b..fa97909c2 100644 --- a/src/Report/Xml/Unit.php +++ b/src/Report/Xml/Unit.php @@ -47,8 +47,16 @@ public function __construct( $node->setAttribute('name', $namespace); } - public function addMethod(string $name): Method - { + public function addMethod( + string $name, + string $signature, + string $start, + ?string $end, + string $executable, + string $executed, + string $coverage, + string $crap + ): void { $node = $this->contextNode->appendChild( $this->contextNode->ownerDocument->createElementNS( Facade::XML_NAMESPACE, @@ -58,6 +66,16 @@ public function addMethod(string $name): Method assert($node instanceof DOMElement); - return new Method($node, $name); + new Method( + $node, + $name, + $signature, + $start, + $end, + $executable, + $executed, + $coverage, + $crap, + ); } }