Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support PHPStan param-closure-this #3103

Open
Kerigard opened this issue Oct 26, 2024 · 1 comment
Open

Add support PHPStan param-closure-this #3103

Kerigard opened this issue Oct 26, 2024 · 1 comment

Comments

@Kerigard
Copy link

Feature description or problem with existing feature

Some Laravel classes provide the ability to add custom methods via closures, but when using them you have to specify the type for $this every time.

Collection::macro('square', function () {
    /** @var \Illuminate\Support\Collection $this */
    return $this->map(fn ($value) => pow($value, 2));
});

Describe the solution you'd like

The macro method uses the @param-closure-this tag to change the value of $this. If support for this tag is implemented, then you will not have to specify the type using @var.

/**
 * @param-closure-this static $macro
 */
public static function macro(string $name, object|callable $macro)

Additional context

https://phpstan.org/writing-php-code/phpdocs-basics#callables

/**
 * @param-closure-this Bar $cb
 */
function doFoo(Closure $cb)
{
    $cb->bindTo(new Bar());
    // ...
}

doFoo(function () {
    // $this is Bar
});
@eznix86
Copy link

eznix86 commented Dec 23, 2024

I personally email @bmewburn with something related, and he referenced this issue, he said:

We plan on implementing it but I don't have an ETA for now.

I think we will have this resolved eventually but without an ETA not sure when.

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

No branches or pull requests

2 participants