77use PHPStan \Parser \LastConditionVisitor ;
88use PHPStan \Rules \Rule ;
99use PHPStan \Rules \RuleErrorBuilder ;
10+ use PHPStan \TrinaryLogic ;
1011use PHPStan \Type \Constant \ConstantBooleanType ;
1112use PHPStan \Type \VerbosityLevel ;
1213use function sprintf ;
@@ -61,13 +62,32 @@ public function processNode(Node $node, Scope $scope): array
6162 return $ ruleErrorBuilder ->treatPhpDocTypesAsCertainTip ();
6263 };
6364
65+ $ verbosity = VerbosityLevel::value ();
66+ if (
67+ (
68+ $ leftType ->isConstantScalarValue ()->yes ()
69+ && $ leftType ->isString ()->yes ()
70+ && $ rightType ->isConstantScalarValue ()->no ()
71+ && $ rightType ->isString ()->yes ()
72+ && TrinaryLogic::extremeIdentity ($ leftType ->isLowercaseString (), $ rightType ->isLowercaseString ())->maybe ()
73+ ) || (
74+ $ rightType ->isConstantScalarValue ()->yes ()
75+ && $ rightType ->isString ()->yes ()
76+ && $ leftType ->isConstantScalarValue ()->no ()
77+ && $ leftType ->isString ()->yes ()
78+ && TrinaryLogic::extremeIdentity ($ leftType ->isLowercaseString (), $ rightType ->isLowercaseString ())->maybe ()
79+ )
80+ ) {
81+ $ verbosity = VerbosityLevel::precise ();
82+ }
83+
6484 if (!$ nodeType ->getValue ()) {
6585 return [
6686 $ addTip (RuleErrorBuilder::message (sprintf (
6787 'Strict comparison using %s between %s and %s will always evaluate to false. ' ,
6888 $ node ->getOperatorSigil (),
69- $ leftType ->describe (VerbosityLevel:: value () ),
70- $ rightType ->describe (VerbosityLevel:: value () ),
89+ $ leftType ->describe ($ verbosity ),
90+ $ rightType ->describe ($ verbosity ),
7191 )))->identifier (sprintf ('%s.alwaysFalse ' , $ node instanceof Node \Expr \BinaryOp \Identical ? 'identical ' : 'notIdentical ' ))->build (),
7292 ];
7393 } elseif ($ this ->checkAlwaysTrueStrictComparison ) {
@@ -79,8 +99,8 @@ public function processNode(Node $node, Scope $scope): array
7999 $ errorBuilder = $ addTip (RuleErrorBuilder::message (sprintf (
80100 'Strict comparison using %s between %s and %s will always evaluate to true. ' ,
81101 $ node ->getOperatorSigil (),
82- $ leftType ->describe (VerbosityLevel:: value () ),
83- $ rightType ->describe (VerbosityLevel:: value () ),
102+ $ leftType ->describe ($ verbosity ),
103+ $ rightType ->describe ($ verbosity ),
84104 )));
85105 if ($ isLast === false && !$ this ->reportAlwaysTrueInLastCondition ) {
86106 $ errorBuilder ->addTip ('Remove remaining cases below this one and this error will disappear too. ' );
0 commit comments