@@ -84,7 +84,14 @@ public function processNode(Node $node, Scope&NodeCallbackInvoker&CollectedDataE
8484 return [];
8585 }
8686
87- $ addTip = function (RuleErrorBuilder $ ruleErrorBuilder ) use ($ scope , $ node ): RuleErrorBuilder {
87+ $ exprType = $ this ->treatPhpDocTypesAsCertain ? $ scope ->getType ($ node ->expr ) : $ scope ->getNativeType ($ node ->expr );
88+ $ reasons = $ classType ->isSuperTypeOf ($ exprType )->reasons ;
89+
90+ $ addTip = function (RuleErrorBuilder $ ruleErrorBuilder ) use ($ scope , $ node , $ reasons ): RuleErrorBuilder {
91+ if ($ reasons !== []) {
92+ return $ this ->possiblyImpureTipHelper ->addTip ($ scope , $ node , $ ruleErrorBuilder ->acceptsReasonsTip ($ reasons ));
93+ }
94+
8895 if (!$ this ->treatPhpDocTypesAsCertain ) {
8996 return $ this ->possiblyImpureTipHelper ->addTip ($ scope , $ node , $ ruleErrorBuilder );
9097 }
@@ -104,19 +111,11 @@ public function processNode(Node $node, Scope&NodeCallbackInvoker&CollectedDataE
104111 };
105112
106113 if (!$ instanceofType ->getValue ()) {
107- $ exprType = $ this ->treatPhpDocTypesAsCertain ? $ scope ->getType ($ node ->expr ) : $ scope ->getNativeType ($ node ->expr );
108-
109- $ errorBuilder = RuleErrorBuilder ::message (sprintf (
114+ $ errorBuilder = $ addTip (RuleErrorBuilder ::message (sprintf (
110115 'Instanceof between %s and %s will always evaluate to false. ' ,
111116 $ exprType ->describe (VerbosityLevel ::typeOnly ()),
112117 $ classType ->describe (VerbosityLevel ::getRecommendedLevelByType ($ classType )),
113- ));
114- $ reasons = $ classType ->isSuperTypeOf ($ exprType )->reasons ;
115- if ($ reasons !== []) {
116- $ errorBuilder = $ this ->possiblyImpureTipHelper ->addTip ($ scope , $ node , $ errorBuilder ->acceptsReasonsTip ($ reasons ));
117- } else {
118- $ errorBuilder = $ addTip ($ errorBuilder );
119- }
118+ )));
120119 $ ruleError = $ errorBuilder ->identifier ('instanceof.alwaysFalse ' )->build ();
121120 if ($ scope ->isInTrait ()) {
122121 $ this ->constantConditionInTraitHelper ->emitError (self ::class, $ scope , $ node , false , $ ruleError );
@@ -132,7 +131,6 @@ public function processNode(Node $node, Scope&NodeCallbackInvoker&CollectedDataE
132131 return [];
133132 }
134133
135- $ exprType = $ this ->treatPhpDocTypesAsCertain ? $ scope ->getType ($ node ->expr ) : $ scope ->getNativeType ($ node ->expr );
136134 $ errorBuilder = $ addTip (RuleErrorBuilder ::message (sprintf (
137135 'Instanceof between %s and %s will always evaluate to true. ' ,
138136 $ exprType ->describe (VerbosityLevel ::typeOnly ()),
0 commit comments