@@ -40,11 +40,32 @@ public function __construct(
4040 }
4141
4242 /**
43- * @param class-string<Rule<covariant Node>> $ruleName
43+ * @param class-string<Rule<covariant Node>>|null $ruleName
4444 * @param ErrorIdentifier $identifier
4545 * @param callable(Type): ?string $typeMessageCallback
4646 */
47- public function check (Expr $ expr , Scope &NodeCallbackInvoker &CollectedDataEmitter $ scope , string $ operatorDescription , string $ identifier , callable $ typeMessageCallback , string $ ruleName , Expr $ originalExpr , ?IdentifierRuleError $ error = null ): ?IdentifierRuleError
47+ public function check (Expr $ expr , Scope &NodeCallbackInvoker &CollectedDataEmitter $ scope , string $ operatorDescription , string $ identifier , callable $ typeMessageCallback , ?string $ ruleName = null , ?IdentifierRuleError $ error = null ): ?IdentifierRuleError
48+ {
49+ $ result = $ this ->checkInternal ($ expr , $ scope , $ operatorDescription , $ identifier , $ typeMessageCallback , $ ruleName , $ expr , $ error );
50+
51+ if ($ ruleName !== null && $ scope ->isInTrait ()) {
52+ if ($ result !== null ) {
53+ $ this ->constantConditionInTraitHelper ->emitError ($ ruleName , $ scope , $ expr , true , $ result );
54+ return null ;
55+ }
56+ $ this ->constantConditionInTraitHelper ->emitNoError ($ ruleName , $ scope , $ expr );
57+ return null ;
58+ }
59+
60+ return $ result ;
61+ }
62+
63+ /**
64+ * @param class-string<Rule<covariant Node>>|null $ruleName
65+ * @param ErrorIdentifier $identifier
66+ * @param callable(Type): ?string $typeMessageCallback
67+ */
68+ private function checkInternal (Expr $ expr , Scope &NodeCallbackInvoker &CollectedDataEmitter $ scope , string $ operatorDescription , string $ identifier , callable $ typeMessageCallback , ?string $ ruleName , Expr $ originalExpr , ?IdentifierRuleError $ error = null ): ?IdentifierRuleError
4869 {
4970 // mirrored in PHPStan\Analyser\MutatingScope::issetCheck()
5071 if ($ expr instanceof Node \Expr \Variable && is_string ($ expr ->name )) {
@@ -119,7 +140,7 @@ public function check(Expr $expr, Scope&NodeCallbackInvoker&CollectedDataEmitter
119140 ), $ typeMessageCallback , $ identifier , 'offset ' );
120141
121142 if ($ error !== null ) {
122- return $ this ->check ($ expr ->var , $ scope , $ operatorDescription , $ identifier , $ typeMessageCallback , $ ruleName , $ originalExpr , $ error );
143+ return $ this ->checkInternal ($ expr ->var , $ scope , $ operatorDescription , $ identifier , $ typeMessageCallback , $ ruleName , $ originalExpr , $ error );
123144 }
124145 }
125146
@@ -225,11 +246,11 @@ static function (Type $type) use ($typeMessageCallback): ?string {
225246
226247 if ($ error !== null ) {
227248 if ($ expr instanceof Node \Expr \PropertyFetch) {
228- return $ this ->check ($ expr ->var , $ scope , $ operatorDescription , $ identifier , $ typeMessageCallback , $ ruleName , $ originalExpr , $ error );
249+ return $ this ->checkInternal ($ expr ->var , $ scope , $ operatorDescription , $ identifier , $ typeMessageCallback , $ ruleName , $ originalExpr , $ error );
229250 }
230251
231252 if ($ expr ->class instanceof Expr) {
232- return $ this ->check ($ expr ->class , $ scope , $ operatorDescription , $ identifier , $ typeMessageCallback , $ ruleName , $ originalExpr , $ error );
253+ return $ this ->checkInternal ($ expr ->class , $ scope , $ operatorDescription , $ identifier , $ typeMessageCallback , $ ruleName , $ originalExpr , $ error );
233254 }
234255 }
235256
@@ -270,27 +291,6 @@ static function (Type $type) use ($typeMessageCallback): ?string {
270291 return null ;
271292 }
272293
273- /**
274- * @param class-string<Rule<covariant Node>> $ruleName
275- * @param ErrorIdentifier $identifier
276- * @param callable(Type): ?string $typeMessageCallback
277- */
278- public function checkWithTraitHandling (Expr $ expr , Scope &NodeCallbackInvoker &CollectedDataEmitter $ scope , string $ operatorDescription , string $ identifier , callable $ typeMessageCallback , string $ ruleName ): ?IdentifierRuleError
279- {
280- $ error = $ this ->check ($ expr , $ scope , $ operatorDescription , $ identifier , $ typeMessageCallback , $ ruleName , $ expr );
281-
282- if ($ scope ->isInTrait ()) {
283- if ($ error !== null ) {
284- $ this ->constantConditionInTraitHelper ->emitError ($ ruleName , $ scope , $ expr , true , $ error );
285- return null ;
286- }
287- $ this ->constantConditionInTraitHelper ->emitNoError ($ ruleName , $ scope , $ expr );
288- return null ;
289- }
290-
291- return $ error ;
292- }
293-
294294 /**
295295 * @param ErrorIdentifier $identifier
296296 */
0 commit comments