Skip to content

Commit

Permalink
Reapply "Fix issues identified by Psalm"
Browse files Browse the repository at this point in the history
This reverts commit b4c435e.
  • Loading branch information
sebastianbergmann committed Feb 4, 2024
1 parent 45fc5ad commit 02c1d45
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Framework/Constraint/String/StringContains.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private function getDetectedEncoding(mixed $other): string

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

if (!$detectedEncoding) {
if ($detectedEncoding === false) {
return 'Encoding detection failed';
}

Expand Down
2 changes: 1 addition & 1 deletion src/Framework/TestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ private function saveConfigurationForChildProcess(): string
{
$path = tempnam(sys_get_temp_dir(), 'phpunit_');

if (!$path) {
if ($path === false) {
throw new ProcessIsolationException;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/Api/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private function dataProvidedByTestWithAnnotation(string $className, string $met
{
$docComment = (new ReflectionMethod($className, $methodName))->getDocComment();

if (!$docComment) {
if ($docComment === false) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Runner/PhptTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ public function run(): void
$failure = new PhptAssertionFailedError(
$e->getMessage(),
0,
$trace[0]['file'],
$trace[0]['line'],
(string) $trace[0]['file'],
(int) $trace[0]['line'],
$trace,
$comparisonFailure ? $diff : '',
);
Expand Down
4 changes: 2 additions & 2 deletions src/TextUI/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ private function buildCliConfiguration(array $argv): CliConfiguration

private function loadXmlConfiguration(false|string $configurationFile): XmlConfiguration
{
if (!$configurationFile) {
if ($configurationFile === false) {
return DefaultConfiguration::create();
}

Expand Down Expand Up @@ -387,7 +387,7 @@ private function executeCommandsThatOnlyRequireCliConfiguration(CliConfiguration
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/TextUI/Configuration/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function build(array $argv): Configuration
$configurationFile = (new XmlConfigurationFileFinder)->find($cliConfiguration);
$xmlConfiguration = DefaultConfiguration::create();

if ($configurationFile) {
if ($configurationFile !== false) {
$xmlConfiguration = (new Loader)->load($configurationFile);
}

Expand Down
4 changes: 2 additions & 2 deletions src/TextUI/Configuration/Cli/XmlConfigurationFileFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function find(Configuration $configuration): false|string
if (is_dir($configuration->configurationFile())) {
$candidate = $this->configurationFileInDirectory($configuration->configurationFile());

if ($candidate) {
if ($candidate !== false) {
return $candidate;
}

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

if ($candidate) {
if ($candidate !== false) {
return $candidate;
}
}
Expand Down
23 changes: 18 additions & 5 deletions src/TextUI/Configuration/Xml/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ private function codeCoverage(string $filename, DOMXPath $xpath): CodeCoverage
);
}

private function getBoolean(string $value, bool|string $default): bool|string
private function getBoolean(string $value, bool $default): bool
{
if (strtolower($value) === 'false') {
return false;
Expand All @@ -487,6 +487,19 @@ private function getBoolean(string $value, bool|string $default): bool|string
return $default;
}

private function getValue(string $value): bool|string
{
if (strtolower($value) === 'false') {
return false;
}

if (strtolower($value) === 'true') {
return true;
}

return $value;
}

private function readFilterDirectories(string $filename, DOMXPath $xpath, string $query): FilterDirectoryCollection
{
$directories = [];
Expand Down Expand Up @@ -556,7 +569,7 @@ private function getBooleanAttribute(DOMElement $element, string $attribute, boo
return $default;
}

return (bool) $this->getBoolean(
return $this->getBoolean(
$element->getAttribute($attribute),
false,
);
Expand Down Expand Up @@ -635,7 +648,7 @@ private function php(string $filename, DOMXPath $xpath): Php

$constants[] = new Constant(
$const->getAttribute('name'),
$this->getBoolean($value, $value),
$this->getValue($value),
);
}

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

if ($var->hasAttribute('force')) {
$force = (bool) $this->getBoolean($var->getAttribute('force'), false);
$force = $this->getBoolean($var->getAttribute('force'), false);
}

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

if (!$verbatim) {
$value = $this->getBoolean($value, $value);
$value = $this->getValue($value);
}

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

0 comments on commit 02c1d45

Please sign in to comment.