Skip to content

Commit 3c97001

Browse files
Refactor
1 parent ecaca17 commit 3c97001

File tree

7 files changed

+18
-18
lines changed

7 files changed

+18
-18
lines changed

src/CodeCoverage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function __serialize(): array
103103
public function getReport(): Directory
104104
{
105105
if ($this->cachedReport === null) {
106-
$this->cachedReport = (new Builder($this->analyser()))->build($this);
106+
$this->cachedReport = new Builder($this->analyser())->build($this);
107107
}
108108

109109
return $this->cachedReport;

src/Node/File.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ private function calculateStatistics(array $classes, array $traits, array $funct
363363
$methodPathCoverage = $method->executablePaths > 0 ? ($method->executedPaths / $method->executablePaths) * 100 : 0;
364364

365365
$method->coverage = $methodBranchCoverage > 0 ? $methodBranchCoverage : $methodLineCoverage;
366-
$method->crap = (new CrapIndex($method->ccn, $methodPathCoverage > 0 ? $methodPathCoverage : $methodLineCoverage))->asString();
366+
$method->crap = new CrapIndex($method->ccn, $methodPathCoverage > 0 ? $methodPathCoverage : $methodLineCoverage)->asString();
367367

368368
$trait->ccn += $method->ccn;
369369
}
@@ -375,7 +375,7 @@ private function calculateStatistics(array $classes, array $traits, array $funct
375375
$traitPathCoverage = $trait->executablePaths > 0 ? ($trait->executedPaths / $trait->executablePaths) * 100 : 0;
376376

377377
$trait->coverage = $traitBranchCoverage > 0 ? $traitBranchCoverage : $traitLineCoverage;
378-
$trait->crap = (new CrapIndex($trait->ccn, $traitPathCoverage > 0 ? $traitPathCoverage : $traitLineCoverage))->asString();
378+
$trait->crap = new CrapIndex($trait->ccn, $traitPathCoverage > 0 ? $traitPathCoverage : $traitLineCoverage)->asString();
379379

380380
if ($trait->executableLines > 0 && $trait->coverage === 100) {
381381
$this->numTestedClasses++;
@@ -391,7 +391,7 @@ private function calculateStatistics(array $classes, array $traits, array $funct
391391
$methodPathCoverage = $method->executablePaths > 0 ? ($method->executedPaths / $method->executablePaths) * 100 : 0;
392392

393393
$method->coverage = $methodBranchCoverage > 0 ? $methodBranchCoverage : $methodLineCoverage;
394-
$method->crap = (new CrapIndex($method->ccn, $methodPathCoverage > 0 ? $methodPathCoverage : $methodLineCoverage))->asString();
394+
$method->crap = new CrapIndex($method->ccn, $methodPathCoverage > 0 ? $methodPathCoverage : $methodLineCoverage)->asString();
395395

396396
$class->ccn += $method->ccn;
397397
}
@@ -403,7 +403,7 @@ private function calculateStatistics(array $classes, array $traits, array $funct
403403
$classPathCoverage = $class->executablePaths > 0 ? ($class->executedPaths / $class->executablePaths) * 100 : 0;
404404

405405
$class->coverage = $classBranchCoverage > 0 ? $classBranchCoverage : $classLineCoverage;
406-
$class->crap = (new CrapIndex($class->ccn, $classPathCoverage > 0 ? $classPathCoverage : $classLineCoverage))->asString();
406+
$class->crap = new CrapIndex($class->ccn, $classPathCoverage > 0 ? $classPathCoverage : $classLineCoverage)->asString();
407407

408408
if ($class->executableLines > 0 && $class->coverage === 100) {
409409
$this->numTestedClasses++;
@@ -418,7 +418,7 @@ private function calculateStatistics(array $classes, array $traits, array $funct
418418
$functionPathCoverage = $function->executablePaths > 0 ? ($function->executedPaths / $function->executablePaths) * 100 : 0;
419419

420420
$function->coverage = $functionBranchCoverage > 0 ? $functionBranchCoverage : $functionLineCoverage;
421-
$function->crap = (new CrapIndex($function->ccn, $functionPathCoverage > 0 ? $functionPathCoverage : $functionLineCoverage))->asString();
421+
$function->crap = new CrapIndex($function->ccn, $functionPathCoverage > 0 ? $functionPathCoverage : $functionLineCoverage)->asString();
422422

423423
if ($function->coverage === 100) {
424424
$this->numTestedFunctions++;

src/Report/Text.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
use SebastianBergmann\CodeCoverage\Node\File;
2222
use SebastianBergmann\CodeCoverage\Util\Percentage;
2323

24-
final class Text
24+
final readonly class Text
2525
{
2626
private const string COLOR_GREEN = "\x1b[30;42m";
2727
private const string COLOR_YELLOW = "\x1b[30;43m";
2828
private const string COLOR_RED = "\x1b[37;41m";
2929
private const string COLOR_HEADER = "\x1b[1;37;40m";
3030
private const string COLOR_RESET = "\x1b[0m";
31-
private readonly Thresholds $thresholds;
32-
private readonly bool $showUncoveredFiles;
33-
private readonly bool $showOnlySummary;
31+
private Thresholds $thresholds;
32+
private bool $showUncoveredFiles;
33+
private bool $showOnlySummary;
3434

3535
public function __construct(Thresholds $thresholds, bool $showUncoveredFiles = false, bool $showOnlySummary = false)
3636
{
@@ -141,7 +141,7 @@ public function process(CodeCoverage $coverage, bool $showColors = false): strin
141141
$report->numberOfExecutableLines(),
142142
);
143143

144-
$padding = max(array_map('strlen', [$classes, $methods, $lines]));
144+
$padding = max(array_map(strlen(...), [$classes, $methods, $lines]));
145145

146146
if ($this->showOnlySummary) {
147147
$title = 'Code Coverage Report Summary:';

src/Report/Xml/Coverage.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
/**
1515
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
1616
*/
17-
final class Coverage
17+
final readonly class Coverage
1818
{
19-
private readonly XMLWriter $xmlWriter;
20-
private readonly string $line;
19+
private XMLWriter $xmlWriter;
20+
private string $line;
2121

2222
public function __construct(
2323
XMLWriter $xmlWriter,

src/Report/Xml/Source.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ public function __construct(XMLWriter $xmlWriter)
2929
public function setSourceCode(string $source): void
3030
{
3131
$tokens = (new Tokenizer)->parse($source);
32-
(new XMLSerializer(new NamespaceUri(Facade::XML_NAMESPACE)))->appendToWriter($this->xmlWriter, $tokens);
32+
new XMLSerializer(new NamespaceUri(Facade::XML_NAMESPACE))->appendToWriter($this->xmlWriter, $tokens);
3333
}
3434
}

src/Version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class Version
1919
public static function id(): string
2020
{
2121
if (self::$version === '') {
22-
self::$version = (new VersionId('12.5.2', dirname(__DIR__)))->asString();
22+
self::$version = new VersionId('12.5.2', dirname(__DIR__))->asString();
2323
}
2424

2525
return self::$version;

tests/_files/source_for_branched_exec_lines.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ class // 0
454454
implements // 0
455455
\Throwable // 0
456456
{ // 0
457-
private const MY_CONST = 1;
457+
private const int MY_CONST = 1;
458458
private $var = 1;
459459
public function myMethod()
460460
{
@@ -596,7 +596,7 @@ abstract class MyAbstractClass implements MyInterface
596596
final class MyFinalClass extends MyAbstractClass
597597
{
598598
use MyTrait;
599-
public const STRUCT = [
599+
public const array STRUCT = [
600600
'foo' => 'bar',
601601
];
602602
private string $var;

0 commit comments

Comments
 (0)