Skip to content

Commit 02c1d45

Browse files
Reapply "Fix issues identified by Psalm"
This reverts commit b4c435e.
1 parent 45fc5ad commit 02c1d45

File tree

8 files changed

+28
-15
lines changed

8 files changed

+28
-15
lines changed

src/Framework/Constraint/String/StringContains.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private function getDetectedEncoding(mixed $other): string
127127

128128
$detectedEncoding = mb_detect_encoding($other, null, true);
129129

130-
if (!$detectedEncoding) {
130+
if ($detectedEncoding === false) {
131131
return 'Encoding detection failed';
132132
}
133133

src/Framework/TestRunner.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ private function saveConfigurationForChildProcess(): string
451451
{
452452
$path = tempnam(sys_get_temp_dir(), 'phpunit_');
453453

454-
if (!$path) {
454+
if ($path === false) {
455455
throw new ProcessIsolationException;
456456
}
457457

src/Metadata/Api/DataProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ private function dataProvidedByTestWithAnnotation(string $className, string $met
236236
{
237237
$docComment = (new ReflectionMethod($className, $methodName))->getDocComment();
238238

239-
if (!$docComment) {
239+
if ($docComment === false) {
240240
return null;
241241
}
242242

src/Runner/PhptTestCase.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ public function run(): void
217217
$failure = new PhptAssertionFailedError(
218218
$e->getMessage(),
219219
0,
220-
$trace[0]['file'],
221-
$trace[0]['line'],
220+
(string) $trace[0]['file'],
221+
(int) $trace[0]['line'],
222222
$trace,
223223
$comparisonFailure ? $diff : '',
224224
);

src/TextUI/Application.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ private function buildCliConfiguration(array $argv): CliConfiguration
332332

333333
private function loadXmlConfiguration(false|string $configurationFile): XmlConfiguration
334334
{
335-
if (!$configurationFile) {
335+
if ($configurationFile === false) {
336336
return DefaultConfiguration::create();
337337
}
338338

@@ -387,7 +387,7 @@ private function executeCommandsThatOnlyRequireCliConfiguration(CliConfiguration
387387
}
388388

389389
if ($cliConfiguration->migrateConfiguration()) {
390-
if (!$configurationFile) {
390+
if ($configurationFile === false) {
391391
$this->exitWithErrorMessage('No configuration file found to migrate');
392392
}
393393

src/TextUI/Configuration/Builder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function build(array $argv): Configuration
3333
$configurationFile = (new XmlConfigurationFileFinder)->find($cliConfiguration);
3434
$xmlConfiguration = DefaultConfiguration::create();
3535

36-
if ($configurationFile) {
36+
if ($configurationFile !== false) {
3737
$xmlConfiguration = (new Loader)->load($configurationFile);
3838
}
3939

src/TextUI/Configuration/Cli/XmlConfigurationFileFinder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function find(Configuration $configuration): false|string
2727
if (is_dir($configuration->configurationFile())) {
2828
$candidate = $this->configurationFileInDirectory($configuration->configurationFile());
2929

30-
if ($candidate) {
30+
if ($candidate !== false) {
3131
return $candidate;
3232
}
3333

@@ -40,7 +40,7 @@ public function find(Configuration $configuration): false|string
4040
if ($useDefaultConfiguration) {
4141
$candidate = $this->configurationFileInDirectory(getcwd());
4242

43-
if ($candidate) {
43+
if ($candidate !== false) {
4444
return $candidate;
4545
}
4646
}

src/TextUI/Configuration/Xml/Loader.php

+18-5
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ private function codeCoverage(string $filename, DOMXPath $xpath): CodeCoverage
474474
);
475475
}
476476

477-
private function getBoolean(string $value, bool|string $default): bool|string
477+
private function getBoolean(string $value, bool $default): bool
478478
{
479479
if (strtolower($value) === 'false') {
480480
return false;
@@ -487,6 +487,19 @@ private function getBoolean(string $value, bool|string $default): bool|string
487487
return $default;
488488
}
489489

490+
private function getValue(string $value): bool|string
491+
{
492+
if (strtolower($value) === 'false') {
493+
return false;
494+
}
495+
496+
if (strtolower($value) === 'true') {
497+
return true;
498+
}
499+
500+
return $value;
501+
}
502+
490503
private function readFilterDirectories(string $filename, DOMXPath $xpath, string $query): FilterDirectoryCollection
491504
{
492505
$directories = [];
@@ -556,7 +569,7 @@ private function getBooleanAttribute(DOMElement $element, string $attribute, boo
556569
return $default;
557570
}
558571

559-
return (bool) $this->getBoolean(
572+
return $this->getBoolean(
560573
$element->getAttribute($attribute),
561574
false,
562575
);
@@ -635,7 +648,7 @@ private function php(string $filename, DOMXPath $xpath): Php
635648

636649
$constants[] = new Constant(
637650
$const->getAttribute('name'),
638-
$this->getBoolean($value, $value),
651+
$this->getValue($value),
639652
);
640653
}
641654

@@ -660,15 +673,15 @@ private function php(string $filename, DOMXPath $xpath): Php
660673
$verbatim = false;
661674

662675
if ($var->hasAttribute('force')) {
663-
$force = (bool) $this->getBoolean($var->getAttribute('force'), false);
676+
$force = $this->getBoolean($var->getAttribute('force'), false);
664677
}
665678

666679
if ($var->hasAttribute('verbatim')) {
667680
$verbatim = $this->getBoolean($var->getAttribute('verbatim'), false);
668681
}
669682

670683
if (!$verbatim) {
671-
$value = $this->getBoolean($value, $value);
684+
$value = $this->getValue($value);
672685
}
673686

674687
$variables[$array][] = new Variable($name, $value, $force);

0 commit comments

Comments
 (0)