Skip to content

Commit 0dd9a85

Browse files
Fix
Co-authored-by: Vincent Langlet <[email protected]>
1 parent a7a4e32 commit 0dd9a85

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/Rules/Comparison/ConstantLooseComparisonRule.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use PHPStan\Rules\Rule;
99
use PHPStan\Rules\RuleErrorBuilder;
1010
use PHPStan\Type\VerbosityLevel;
11-
use function in_array;
1211
use function sprintf;
1312

1413
/**
@@ -57,7 +56,7 @@ public function processNode(Node $node, Scope $scope): array
5756
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
5857
};
5958

60-
if (in_array(false, $nodeType->getConstantScalarValues(), true)) {
59+
if ($nodeType->isFalse()->yes()) {
6160
return [
6261
$addTip(RuleErrorBuilder::message(sprintf(
6362
'Loose comparison using %s between %s and %s will always evaluate to false.',

src/Rules/Comparison/ImpossibleCheckTypeHelper.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
use function count;
3636
use function implode;
3737
use function in_array;
38-
use function is_bool;
3938
use function is_string;
4039
use function sprintf;
4140
use function strtolower;
@@ -69,12 +68,13 @@ public function findSpecifiedType(
6968
$functionName = strtolower((string) $node->name);
7069
if ($functionName === 'assert' && $argsCount >= 1) {
7170
$arg = $node->getArgs()[0]->value;
72-
$assertValues = ($this->treatPhpDocTypesAsCertain ? $scope->getType($arg) : $scope->getNativeType($arg))->getConstantScalarValues();
73-
if (count($assertValues) !== 1 || !is_bool($assertValues[0])) {
71+
$assertValue = ($this->treatPhpDocTypesAsCertain ? $scope->getType($arg) : $scope->getNativeType($arg))->toBoolean();
72+
if (! $assertValue->isTrue()->yes() && ! $assertValue->isFalse()->yes()) {
7473
return null;
7574
}
7675

77-
return $assertValues[0];
76+
/** @var bool */
77+
return $assertValue->getConstantScalarValues()[0];
7878
}
7979
if (in_array($functionName, [
8080
'class_exists',

0 commit comments

Comments
 (0)