Skip to content

Commit de39d9d

Browse files
Use stricter comparison
1 parent fc1ce26 commit de39d9d

File tree

9 files changed

+35
-35
lines changed

9 files changed

+35
-35
lines changed

src/Driver/PcovDriver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function stop(): RawCodeCoverageData
5454
$filesToCollectCoverageFor = waiting();
5555
$collected = [];
5656

57-
if ($filesToCollectCoverageFor) {
57+
if ($filesToCollectCoverageFor !== []) {
5858
if (!$this->filter->isEmpty()) {
5959
$filesToCollectCoverageFor = array_intersect($filesToCollectCoverageFor, $this->filter->files());
6060
}

src/Node/File.php

+25-25
Original file line numberDiff line numberDiff line change
@@ -404,24 +404,24 @@ private function calculateStatistics(array $classes, array $traits, array $funct
404404

405405
foreach ($this->traits as &$trait) {
406406
foreach ($trait['methods'] as &$method) {
407-
$methodLineCoverage = $method['executableLines'] ? ($method['executedLines'] / $method['executableLines']) * 100 : 100;
408-
$methodBranchCoverage = $method['executableBranches'] ? ($method['executedBranches'] / $method['executableBranches']) * 100 : 0;
409-
$methodPathCoverage = $method['executablePaths'] ? ($method['executedPaths'] / $method['executablePaths']) * 100 : 0;
407+
$methodLineCoverage = $method['executableLines'] > 0 ? ($method['executedLines'] / $method['executableLines']) * 100 : 100;
408+
$methodBranchCoverage = $method['executableBranches'] > 0 ? ($method['executedBranches'] / $method['executableBranches']) * 100 : 0;
409+
$methodPathCoverage = $method['executablePaths'] > 0 ? ($method['executedPaths'] / $method['executablePaths']) * 100 : 0;
410410

411-
$method['coverage'] = $methodBranchCoverage ?: $methodLineCoverage;
412-
$method['crap'] = (new CrapIndex($method['ccn'], $methodPathCoverage ?: $methodLineCoverage))->asString();
411+
$method['coverage'] = $methodBranchCoverage > 0 ? $methodBranchCoverage : $methodLineCoverage;
412+
$method['crap'] = (new CrapIndex($method['ccn'], $methodPathCoverage > 0 ? $methodPathCoverage : $methodLineCoverage))->asString();
413413

414414
$trait['ccn'] += $method['ccn'];
415415
}
416416

417417
unset($method);
418418

419-
$traitLineCoverage = $trait['executableLines'] ? ($trait['executedLines'] / $trait['executableLines']) * 100 : 100;
420-
$traitBranchCoverage = $trait['executableBranches'] ? ($trait['executedBranches'] / $trait['executableBranches']) * 100 : 0;
421-
$traitPathCoverage = $trait['executablePaths'] ? ($trait['executedPaths'] / $trait['executablePaths']) * 100 : 0;
419+
$traitLineCoverage = $trait['executableLines'] > 0 ? ($trait['executedLines'] / $trait['executableLines']) * 100 : 100;
420+
$traitBranchCoverage = $trait['executableBranches'] > 0 ? ($trait['executedBranches'] / $trait['executableBranches']) * 100 : 0;
421+
$traitPathCoverage = $trait['executablePaths'] > 0 ? ($trait['executedPaths'] / $trait['executablePaths']) * 100 : 0;
422422

423-
$trait['coverage'] = $traitBranchCoverage ?: $traitLineCoverage;
424-
$trait['crap'] = (new CrapIndex($trait['ccn'], $traitPathCoverage ?: $traitLineCoverage))->asString();
423+
$trait['coverage'] = $traitBranchCoverage > 0 ? $traitBranchCoverage : $traitLineCoverage;
424+
$trait['crap'] = (new CrapIndex($trait['ccn'], $traitPathCoverage > 0 ? $traitPathCoverage : $traitLineCoverage))->asString();
425425

426426
if ($trait['executableLines'] > 0 && $trait['coverage'] === 100) {
427427
$this->numTestedClasses++;
@@ -432,24 +432,24 @@ private function calculateStatistics(array $classes, array $traits, array $funct
432432

433433
foreach ($this->classes as &$class) {
434434
foreach ($class['methods'] as &$method) {
435-
$methodLineCoverage = $method['executableLines'] ? ($method['executedLines'] / $method['executableLines']) * 100 : 100;
436-
$methodBranchCoverage = $method['executableBranches'] ? ($method['executedBranches'] / $method['executableBranches']) * 100 : 0;
437-
$methodPathCoverage = $method['executablePaths'] ? ($method['executedPaths'] / $method['executablePaths']) * 100 : 0;
435+
$methodLineCoverage = $method['executableLines'] > 0 ? ($method['executedLines'] / $method['executableLines']) * 100 : 100;
436+
$methodBranchCoverage = $method['executableBranches'] > 0 ? ($method['executedBranches'] / $method['executableBranches']) * 100 : 0;
437+
$methodPathCoverage = $method['executablePaths'] > 0 ? ($method['executedPaths'] / $method['executablePaths']) * 100 : 0;
438438

439-
$method['coverage'] = $methodBranchCoverage ?: $methodLineCoverage;
440-
$method['crap'] = (new CrapIndex($method['ccn'], $methodPathCoverage ?: $methodLineCoverage))->asString();
439+
$method['coverage'] = $methodBranchCoverage > 0 ? $methodBranchCoverage : $methodLineCoverage;
440+
$method['crap'] = (new CrapIndex($method['ccn'], $methodPathCoverage > 0 ? $methodPathCoverage : $methodLineCoverage))->asString();
441441

442442
$class['ccn'] += $method['ccn'];
443443
}
444444

445445
unset($method);
446446

447-
$classLineCoverage = $class['executableLines'] ? ($class['executedLines'] / $class['executableLines']) * 100 : 100;
448-
$classBranchCoverage = $class['executableBranches'] ? ($class['executedBranches'] / $class['executableBranches']) * 100 : 0;
449-
$classPathCoverage = $class['executablePaths'] ? ($class['executedPaths'] / $class['executablePaths']) * 100 : 0;
447+
$classLineCoverage = $class['executableLines'] > 0 ? ($class['executedLines'] / $class['executableLines']) * 100 : 100;
448+
$classBranchCoverage = $class['executableBranches'] > 0 ? ($class['executedBranches'] / $class['executableBranches']) * 100 : 0;
449+
$classPathCoverage = $class['executablePaths'] > 0 ? ($class['executedPaths'] / $class['executablePaths']) * 100 : 0;
450450

451-
$class['coverage'] = $classBranchCoverage ?: $classLineCoverage;
452-
$class['crap'] = (new CrapIndex($class['ccn'], $classPathCoverage ?: $classLineCoverage))->asString();
451+
$class['coverage'] = $classBranchCoverage > 0 ? $classBranchCoverage : $classLineCoverage;
452+
$class['crap'] = (new CrapIndex($class['ccn'], $classPathCoverage > 0 ? $classPathCoverage : $classLineCoverage))->asString();
453453

454454
if ($class['executableLines'] > 0 && $class['coverage'] === 100) {
455455
$this->numTestedClasses++;
@@ -459,12 +459,12 @@ private function calculateStatistics(array $classes, array $traits, array $funct
459459
unset($class);
460460

461461
foreach ($this->functions as &$function) {
462-
$functionLineCoverage = $function['executableLines'] ? ($function['executedLines'] / $function['executableLines']) * 100 : 100;
463-
$functionBranchCoverage = $function['executableBranches'] ? ($function['executedBranches'] / $function['executableBranches']) * 100 : 0;
464-
$functionPathCoverage = $function['executablePaths'] ? ($function['executedPaths'] / $function['executablePaths']) * 100 : 0;
462+
$functionLineCoverage = $function['executableLines'] > 0 ? ($function['executedLines'] / $function['executableLines']) * 100 : 100;
463+
$functionBranchCoverage = $function['executableBranches'] > 0 ? ($function['executedBranches'] / $function['executableBranches']) * 100 : 0;
464+
$functionPathCoverage = $function['executablePaths'] > 0 ? ($function['executedPaths'] / $function['executablePaths']) * 100 : 0;
465465

466-
$function['coverage'] = $functionBranchCoverage ?: $functionLineCoverage;
467-
$function['crap'] = (new CrapIndex($function['ccn'], $functionPathCoverage ?: $functionLineCoverage))->asString();
466+
$function['coverage'] = $functionBranchCoverage > 0 ? $functionBranchCoverage : $functionLineCoverage;
467+
$function['crap'] = (new CrapIndex($function['ccn'], $functionPathCoverage > 0 ? $functionPathCoverage : $functionLineCoverage))->asString();
468468

469469
if ($function['coverage'] === 100) {
470470
$this->numTestedFunctions++;

src/Report/Html/Renderer/File.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ private function renderSourceWithLineCoverage(FileNode $node): string
537537
$popoverTitle = '';
538538

539539
if (array_key_exists($i, $coverageData)) {
540-
$numTests = ($coverageData[$i] ? count($coverageData[$i]) : 0);
540+
$numTests = ($coverageData[$i] !== null ? count($coverageData[$i]) : 0);
541541

542542
if ($coverageData[$i] === null) {
543543
$trClass = 'warning';

src/Report/Xml/BuildInformation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private function nodeByName(string $name): DOMElement
6666
$name,
6767
)->item(0);
6868

69-
if (!$node) {
69+
if ($node === null) {
7070
$node = $this->contextNode->appendChild(
7171
$this->contextNode->ownerDocument->createElementNS(
7272
'https://schema.phpunit.de/coverage/1.0',

src/Report/Xml/File.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function totals(): Totals
3131
{
3232
$totalsContainer = $this->contextNode->firstChild;
3333

34-
if (!$totalsContainer) {
34+
if ($totalsContainer === null) {
3535
$totalsContainer = $this->contextNode->appendChild(
3636
$this->dom->createElementNS(
3737
'https://schema.phpunit.de/coverage/1.0',
@@ -52,7 +52,7 @@ public function lineCoverage(string $line): Coverage
5252
'coverage',
5353
)->item(0);
5454

55-
if (!$coverage) {
55+
if ($coverage === null) {
5656
$coverage = $this->contextNode->appendChild(
5757
$this->dom->createElementNS(
5858
'https://schema.phpunit.de/coverage/1.0',

src/Report/Xml/Node.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function totals(): Totals
3535
{
3636
$totalsContainer = $this->contextNode()->firstChild;
3737

38-
if (!$totalsContainer) {
38+
if ($totalsContainer === null) {
3939
$totalsContainer = $this->contextNode()->appendChild(
4040
$this->dom->createElementNS(
4141
'https://schema.phpunit.de/coverage/1.0',

src/Report/Xml/Project.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function buildInformation(): BuildInformation
3636
'build',
3737
)->item(0);
3838

39-
if (!$buildNode) {
39+
if ($buildNode === null) {
4040
$buildNode = $this->dom()->documentElement->appendChild(
4141
$this->dom()->createElementNS(
4242
'https://schema.phpunit.de/coverage/1.0',
@@ -57,7 +57,7 @@ public function tests(): Tests
5757
'tests',
5858
)->item(0);
5959

60-
if (!$testsNode) {
60+
if ($testsNode === null) {
6161
$testsNode = $this->contextNode()->appendChild(
6262
$this->dom()->createElementNS(
6363
'https://schema.phpunit.de/coverage/1.0',

src/Report/Xml/Report.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function source(): Source
7171
'source',
7272
)->item(0);
7373

74-
if (!$source) {
74+
if ($source === null) {
7575
$source = $this->contextNode()->appendChild(
7676
$this->dom()->createElementNS(
7777
'https://schema.phpunit.de/coverage/1.0',

src/Report/Xml/Unit.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function setNamespace(string $namespace): void
4545
'namespace',
4646
)->item(0);
4747

48-
if (!$node) {
48+
if ($node === null) {
4949
$node = $this->contextNode->appendChild(
5050
$this->contextNode->ownerDocument->createElementNS(
5151
'https://schema.phpunit.de/coverage/1.0',

0 commit comments

Comments
 (0)