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

[Feature]: Parse accessor attribute type from return value of closure #85

Open
joelstein opened this issue Nov 5, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@joelstein
Copy link

What happened?

Suppose I have the following code:

protected function label(): Attribute
{
    return Attribute::make(
        get: fn (): string => 'Some label',
    );
}

The get function type hints that the return value is "string" but it will produce label?: any.

The docs for this package suggest doing something like this:

/**
 * @return string
 */
protected function label(): Attribute
{
    return Attribute::make(
        get: fn (): string => 'Some label',
    );
}

But that confused my IDE because the PHPDoc doesn't match the function return type.

Is it possible to parse the return type from the Attribute's get closure?

How to reproduce the bug

See above.

Package Version

3.1.03

PHP Version

8.3

Which operating systems does with happen with?

macOS

Notes

No response

@joelstein joelstein added the bug Something isn't working label Nov 5, 2024
@joelstein
Copy link
Author

For what it's worth, the barryvdh/laravel-ide-helper package does this. Perhaps the source code would be worth reviewing for implementation tips.

@ewilan-riviere ewilan-riviere self-assigned this Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants