Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/Type/Accessory/AccessoryDecimalIntegerStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,18 +411,19 @@

public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
{
if ($this->inverse) {
// may be numeric ("02", "2.0") or empty (""), so nothing is decidable
return new BooleanType();
}

// a decimal-int-string is a non-empty numeric string, so it compares
// like one: never loosely equal to null or to a non-numeric string
if ($type->isNull()->yes()) {
return new ConstantBooleanType(false);
}

if ($type->isString()->yes()) {
if ($this->inverse) {
if ($type->isDecimalIntegerString()->yes()) {
return new ConstantBooleanType(false);
}
} elseif ($type->isDecimalIntegerString()->no()) {
return new ConstantBooleanType(false);
}
if ($type->isString()->yes() && $type->isNumericString()->no()) {
return new ConstantBooleanType(false);
}

return new BooleanType();
Expand All @@ -433,7 +434,7 @@
return $this;
}

public function traverseSimultaneously(Type $right, callable $cb): Type

Check warning on line 437 in src/Type/Accessory/AccessoryDecimalIntegerStringType.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ return new ConstantBooleanType(false); } - if ($type->isString()->yes() && $type->isNumericString()->no()) { + if (!$type->isString()->no() && $type->isNumericString()->no()) { return new ConstantBooleanType(false); }

Check warning on line 437 in src/Type/Accessory/AccessoryDecimalIntegerStringType.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ return new ConstantBooleanType(false); } - if ($type->isString()->yes() && $type->isNumericString()->no()) { + if ($type->isString()->yes() && !$type->isNumericString()->yes()) { return new ConstantBooleanType(false); }

Check warning on line 437 in src/Type/Accessory/AccessoryDecimalIntegerStringType.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ return new ConstantBooleanType(false); } - if ($type->isString()->yes() && $type->isNumericString()->no()) { + if ($type->isString()->yes() && !$type->isNumericString()->yes()) { return new ConstantBooleanType(false); }

Check warning on line 437 in src/Type/Accessory/AccessoryDecimalIntegerStringType.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ return new ConstantBooleanType(false); } - if ($type->isString()->yes() && $type->isNumericString()->no()) { + if (!$type->isString()->no() && $type->isNumericString()->no()) { return new ConstantBooleanType(false); }
{
return $this;
}
Expand Down
40 changes: 40 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-14793.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php declare(strict_types = 1);

namespace Bug14793;

use function PHPStan\Testing\assertType;

/**
* @param decimal-int-string $a
* @param non-decimal-int-string $b
* @param numeric-string $n
*/
function foo(string $a, string $b, string $n): void
{
// '2' == '02' and '2' == '2.0' are true in PHP, so these cannot be decided.
assertType('bool', $a == $b);
assertType('bool', $b == $a);
assertType('bool', $a == $n);
assertType('bool', $a == '2.0');
assertType('bool', $a == '02');
}

/**
* @param decimal-int-string $a
*/
function decimalAlwaysFalse(string $a): void
{
// A decimal-int-string is numeric and non-empty: comparing it to a
// non-numeric string or to null can never be loosely equal.
assertType('false', $a == 'foo');
assertType('false', $a == null);
}

/**
* @param non-decimal-int-string $b
*/
function nonDecimalVsNull(string $b): void
{
// '' is a valid non-decimal-int-string and '' == null is true.
assertType('bool', $b == null);
}
Loading