From 837ec4c4206973eed93e4e7a862a92f15f8ff704 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Tue, 12 May 2020 09:12:39 +0200 Subject: [PATCH] Fix issues identified by Psalm --- .psalm/baseline.xml | 8 +------- src/Node/Iterator.php | 2 +- src/Report/Crap4j.php | 2 +- src/Report/Html/Facade.php | 2 +- src/Report/Text.php | 7 +++++-- src/Report/Xml/Report.php | 4 ++-- 6 files changed, 11 insertions(+), 14 deletions(-) diff --git a/.psalm/baseline.xml b/.psalm/baseline.xml index e2a5effdb..646ce3a36 100644 --- a/.psalm/baseline.xml +++ b/.psalm/baseline.xml @@ -1,5 +1,5 @@ - + $unit[0] @@ -81,12 +81,6 @@ $this->nodes[$this->position] - - AbstractNode - - - $this->valid() ? $this->nodes[$this->position] : null - diff --git a/src/Node/Iterator.php b/src/Node/Iterator.php index 2e65fac2a..6fa700f9c 100644 --- a/src/Node/Iterator.php +++ b/src/Node/Iterator.php @@ -56,7 +56,7 @@ public function key(): int /** * Returns the current element. */ - public function current(): AbstractNode + public function current(): ?AbstractNode { return $this->valid() ? $this->nodes[$this->position] : null; } diff --git a/src/Report/Crap4j.php b/src/Report/Crap4j.php index 53dc1ba9d..68a6ee85a 100644 --- a/src/Report/Crap4j.php +++ b/src/Report/Crap4j.php @@ -38,7 +38,7 @@ public function process(CodeCoverage $coverage, ?string $target = null, ?string $project = $document->createElement('project', \is_string($name) ? $name : ''); $root->appendChild($project); - $root->appendChild($document->createElement('timestamp', \date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']))); + $root->appendChild($document->createElement('timestamp', (string) \date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']))); $stats = $document->createElement('stats'); $methodsNode = $document->createElement('methods'); diff --git a/src/Report/Html/Facade.php b/src/Report/Html/Facade.php index 71e3fb5fb..04b607162 100644 --- a/src/Report/Html/Facade.php +++ b/src/Report/Html/Facade.php @@ -60,7 +60,7 @@ public function process(CodeCoverage $coverage, string $target): void $_SERVER['REQUEST_TIME'] = \time(); } - $date = \date('D M j G:i:s T Y', $_SERVER['REQUEST_TIME']); + $date = (string) \date('D M j G:i:s T Y', $_SERVER['REQUEST_TIME']); $dashboard = new Dashboard( $this->templatePath, diff --git a/src/Report/Text.php b/src/Report/Text.php index f123bedd5..1cbbe2ab5 100644 --- a/src/Report/Text.php +++ b/src/Report/Text.php @@ -274,10 +274,13 @@ private function printCoverageCounts(int $numberOfCoveredElements, int $totalNum \sprintf($format, $totalNumberOfElements) . ')'; } - private function format($color, $padding, $string): string + /** + * @param false|string $string + */ + private function format(string $color, int $padding, $string): string { $reset = $color ? self::COLOR_RESET : ''; - return $color . \str_pad($string, $padding) . $reset . \PHP_EOL; + return $color . \str_pad((string) $string, $padding) . $reset . \PHP_EOL; } } diff --git a/src/Report/Xml/Report.php b/src/Report/Xml/Report.php index 74e733e7e..a5bb4fc61 100644 --- a/src/Report/Xml/Report.php +++ b/src/Report/Xml/Report.php @@ -72,13 +72,13 @@ public function getSource(): Source return new Source($source); } - private function setName($name): void + private function setName(string $name): void { $this->getContextNode()->setAttribute('name', \basename($name)); $this->getContextNode()->setAttribute('path', \dirname($name)); } - private function getUnitObject($tagName, $name): Unit + private function getUnitObject(string $tagName, $name): Unit { $node = $this->getContextNode()->appendChild( $this->getDomDocument()->createElementNS(