Skip to content

ForbidCheckedExceptionInCallableRule: resolve static call caller type from expressions - #368

Merged
janedbal merged 2 commits into
shipmonk-rnd:masterfrom
maryo:fix/forbid-checked-exception-in-callable-static-call-expression
Sep 17, 2026
Merged

janedbal merged 2 commits into
shipmonk-rnd:masterfrom
maryo:fix/forbid-checked-exception-in-callable-static-call-expression

Conversation

@maryo

@maryo maryo commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

When a static method is called on anything but a literal class name, the rule ignores @param-immediately-invoked-callable on the target parameter (and allowedCheckedExceptionCallables as well) and reports the callable anyway. Both an object and a class-string in the class part are affected:

$this->instance::invoking(function () {
    throw new CheckedException(); // reported, though invoking() has @param-immediately-invoked-callable
});

$className = MyClass::class;
$className::invoking(function () { throw new CheckedException(); }); // the same

$this->instance::throwing(...); // the reverse: never reported, though it should be

Both whitelistAllowedCallables() and processFirstClassCallable() guarded their StaticCall branch by $node->class instanceof Name. They now resolve the caller type through the scope, the way the MethodCall branch already does; getObjectTypeOrClassStringObjectType() covers objects and class-strings alike. Anything else resolves to ErrorType, finds no method reflection and behaves as before.

Note for the release notes: fixing the missing report can surface new errors on $expr::methodWithThrows(...) in existing codebases.

The second commit is unrelated — FirstClassCallableTest declared testPassedCallbacksA6 twice, so the data file could not be loaded (tests/Rule/data is in the composer classmap).

🤖 Generated with Claude Code

maryo and others added 2 commits August 28, 2026 14:00
… from expressions

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…lbacksA6

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@maryo
maryo marked this pull request as ready for review August 28, 2026 12:49
@janedbal
janedbal merged commit f72b888 into shipmonk-rnd:master Sep 17, 2026
22 checks passed
@janedbal

Copy link
Copy Markdown
Member

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants