Skip to content

Commit 58eabaf

Browse files
Use stricter comparison
1 parent 9c6be7e commit 58eabaf

File tree

6 files changed

+35
-25
lines changed

6 files changed

+35
-25
lines changed

src/TextUI/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ private function exitWithCrashMessage(Throwable $t): never
760760

761761
$first = true;
762762

763-
if ($t->getPrevious()) {
763+
if ($t->getPrevious() !== null) {
764764
$t = $t->getPrevious();
765765
}
766766

src/TextUI/Configuration/Cli/Builder.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,11 @@ public function fromParameters(array $parameters): Configuration
278278

279279
switch ($option[0]) {
280280
case '--colors':
281-
$colors = $option[1] ?: \PHPUnit\TextUI\Configuration\Configuration::COLOR_AUTO;
281+
$colors = \PHPUnit\TextUI\Configuration\Configuration::COLOR_AUTO;
282+
283+
if ($option[1] !== null) {
284+
$colors = $option[1];
285+
}
282286

283287
break;
284288

src/TextUI/Configuration/TestSuiteBuilder.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ public function build(Configuration $configuration): TestSuite
9494
private function testSuiteFromPath(string $path, array $suffixes, ?TestSuite $suite = null): TestSuite
9595
{
9696
if (str_ends_with($path, '.phpt') && is_file($path)) {
97-
$suite = $suite ?: TestSuite::empty($path);
97+
if ($suite === null) {
98+
$suite = TestSuite::empty($path);
99+
}
100+
98101
$suite->addTestFile($path);
99102

100103
return $suite;
@@ -103,7 +106,10 @@ private function testSuiteFromPath(string $path, array $suffixes, ?TestSuite $su
103106
if (is_dir($path)) {
104107
$files = (new FileIteratorFacade)->getFilesAsArray($path, $suffixes);
105108

106-
$suite = $suite ?: TestSuite::empty('CLI Arguments');
109+
if ($suite === null) {
110+
$suite = TestSuite::empty('CLI Arguments');
111+
}
112+
107113
$suite->addTestFiles($files);
108114

109115
return $suite;
@@ -117,7 +123,7 @@ private function testSuiteFromPath(string $path, array $suffixes, ?TestSuite $su
117123
exit(1);
118124
}
119125

120-
if (!$suite) {
126+
if ($suite === null) {
121127
return TestSuite::fromClassReflector($testClass);
122128
}
123129

src/TextUI/Configuration/Xml/Loader.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private function logging(string $filename, DOMXPath $xpath): Logging
132132
$junit = null;
133133
$element = $this->element($xpath, 'logging/junit');
134134

135-
if ($element) {
135+
if ($element !== null) {
136136
$junit = new Junit(
137137
new File(
138138
$this->toAbsolutePath(
@@ -146,7 +146,7 @@ private function logging(string $filename, DOMXPath $xpath): Logging
146146
$teamCity = null;
147147
$element = $this->element($xpath, 'logging/teamcity');
148148

149-
if ($element) {
149+
if ($element !== null) {
150150
$teamCity = new TeamCity(
151151
new File(
152152
$this->toAbsolutePath(
@@ -160,7 +160,7 @@ private function logging(string $filename, DOMXPath $xpath): Logging
160160
$testDoxHtml = null;
161161
$element = $this->element($xpath, 'logging/testdoxHtml');
162162

163-
if ($element) {
163+
if ($element !== null) {
164164
$testDoxHtml = new TestDoxHtml(
165165
new File(
166166
$this->toAbsolutePath(
@@ -174,7 +174,7 @@ private function logging(string $filename, DOMXPath $xpath): Logging
174174
$testDoxText = null;
175175
$element = $this->element($xpath, 'logging/testdoxText');
176176

177-
if ($element) {
177+
if ($element !== null) {
178178
$testDoxText = new TestDoxText(
179179
new File(
180180
$this->toAbsolutePath(
@@ -279,7 +279,7 @@ private function source(string $filename, DOMXPath $xpath): Source
279279

280280
$element = $this->element($xpath, 'source');
281281

282-
if ($element) {
282+
if ($element !== null) {
283283
$baseline = $this->parseStringAttribute($element, 'baseline');
284284

285285
if ($baseline !== null) {
@@ -357,7 +357,7 @@ private function codeCoverage(string $filename, DOMXPath $xpath): CodeCoverage
357357

358358
$element = $this->element($xpath, 'coverage');
359359

360-
if ($element) {
360+
if ($element !== null) {
361361
$pathCoverage = $this->parseBooleanAttribute(
362362
$element,
363363
'pathCoverage',
@@ -386,7 +386,7 @@ private function codeCoverage(string $filename, DOMXPath $xpath): CodeCoverage
386386
$clover = null;
387387
$element = $this->element($xpath, 'coverage/report/clover');
388388

389-
if ($element) {
389+
if ($element !== null) {
390390
$clover = new Clover(
391391
new File(
392392
$this->toAbsolutePath(
@@ -400,7 +400,7 @@ private function codeCoverage(string $filename, DOMXPath $xpath): CodeCoverage
400400
$cobertura = null;
401401
$element = $this->element($xpath, 'coverage/report/cobertura');
402402

403-
if ($element) {
403+
if ($element !== null) {
404404
$cobertura = new Cobertura(
405405
new File(
406406
$this->toAbsolutePath(
@@ -414,7 +414,7 @@ private function codeCoverage(string $filename, DOMXPath $xpath): CodeCoverage
414414
$crap4j = null;
415415
$element = $this->element($xpath, 'coverage/report/crap4j');
416416

417-
if ($element) {
417+
if ($element !== null) {
418418
$crap4j = new Crap4j(
419419
new File(
420420
$this->toAbsolutePath(
@@ -429,7 +429,7 @@ private function codeCoverage(string $filename, DOMXPath $xpath): CodeCoverage
429429
$html = null;
430430
$element = $this->element($xpath, 'coverage/report/html');
431431

432-
if ($element) {
432+
if ($element !== null) {
433433
$defaultColors = Colors::default();
434434
$defaultThresholds = Thresholds::default();
435435

@@ -454,7 +454,7 @@ private function codeCoverage(string $filename, DOMXPath $xpath): CodeCoverage
454454
$php = null;
455455
$element = $this->element($xpath, 'coverage/report/php');
456456

457-
if ($element) {
457+
if ($element !== null) {
458458
$php = new CodeCoveragePhp(
459459
new File(
460460
$this->toAbsolutePath(
@@ -468,7 +468,7 @@ private function codeCoverage(string $filename, DOMXPath $xpath): CodeCoverage
468468
$text = null;
469469
$element = $this->element($xpath, 'coverage/report/text');
470470

471-
if ($element) {
471+
if ($element !== null) {
472472
$text = new CodeCoverageText(
473473
new File(
474474
$this->toAbsolutePath(
@@ -484,7 +484,7 @@ private function codeCoverage(string $filename, DOMXPath $xpath): CodeCoverage
484484
$xml = null;
485485
$element = $this->element($xpath, 'coverage/report/xml');
486486

487-
if ($element) {
487+
if ($element !== null) {
488488
$xml = new CodeCoverageXml(
489489
new Directory(
490490
$this->toAbsolutePath(
@@ -549,7 +549,7 @@ private function readFilterDirectories(string $filename, DOMXPath $xpath, string
549549

550550
$directoryPath = $directoryNode->textContent;
551551

552-
if (!$directoryPath) {
552+
if ($directoryPath === '') {
553553
continue;
554554
}
555555

@@ -576,7 +576,7 @@ private function readFilterFiles(string $filename, DOMXPath $xpath, string $quer
576576

577577
$filePath = $fileNode->textContent;
578578

579-
if ($filePath) {
579+
if ($filePath !== '') {
580580
$files[] = new File($this->toAbsolutePath($filename, $filePath));
581581
}
582582
}
@@ -679,7 +679,7 @@ private function php(string $filename, DOMXPath $xpath): Php
679679

680680
$path = $includePath->textContent;
681681

682-
if ($path) {
682+
if ($path !== '') {
683683
$includePaths[] = new Directory($this->toAbsolutePath($filename, $path));
684684
}
685685
}
@@ -967,7 +967,7 @@ private function testSuite(string $filename, DOMXPath $xpath): TestSuiteCollecti
967967
foreach ($element->getElementsByTagName('exclude') as $excludeNode) {
968968
$excludeFile = $excludeNode->textContent;
969969

970-
if ($excludeFile) {
970+
if ($excludeFile !== '') {
971971
$exclude[] = new File($this->toAbsolutePath($filename, $excludeFile));
972972
}
973973
}

src/TextUI/Configuration/Xml/Migration/Migrations/MoveAttributesFromFilterWhitelistToCoverage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function migrate(DOMDocument $document): void
2626
{
2727
$whitelist = $document->getElementsByTagName('whitelist')->item(0);
2828

29-
if (!$whitelist) {
29+
if ($whitelist === null) {
3030
return;
3131
}
3232

src/TextUI/Configuration/Xml/TestSuiteMapper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
public function map(string $xmlConfigurationFile, TestSuiteCollection $configuredTestSuites, string $namesOfIncludedTestSuites, string $namesOfExcludedTestSuites): TestSuiteObject
4444
{
4545
try {
46-
$namesOfIncludedTestSuitesAsArray = $namesOfIncludedTestSuites ? explode(',', $namesOfIncludedTestSuites) : [];
47-
$excludedTestSuitesAsArray = $namesOfExcludedTestSuites ? explode(',', $namesOfExcludedTestSuites) : [];
46+
$namesOfIncludedTestSuitesAsArray = $namesOfIncludedTestSuites !== '' ? explode(',', $namesOfIncludedTestSuites) : [];
47+
$excludedTestSuitesAsArray = $namesOfExcludedTestSuites !== '' ? explode(',', $namesOfExcludedTestSuites) : [];
4848
$result = TestSuiteObject::empty($xmlConfigurationFile);
4949
$processed = [];
5050

0 commit comments

Comments
 (0)