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

PhanUnreferencedUseNormal reported in constructor promotion #4838

Open
ennorehling opened this issue Feb 19, 2024 · 0 comments
Open

PhanUnreferencedUseNormal reported in constructor promotion #4838

ennorehling opened this issue Feb 19, 2024 · 0 comments

Comments

@ennorehling
Copy link

Phan 5.4.2
php-ast version 1.1.0
PHP version used to run Phan: 8.2.7

On this code:

class FooData extends Spatie\LaravelData\Data {
    public function __construct(
        #[WithTransformer(DateTimeInterfaceTransformer::class)]
        public Carbon $birth_date
    ) {
    }

I get the message:

PhanAttributeWrongTarget Saw use of attribute \Spatie\LaravelData\Attributes\WithTransformer declared at vendor/spatie/laravel-data/src/Attributes/WithTransformer.php:10 which supports being declared on \Attribute::TARGET_CLASS|\Attribute::TARGET_PROPERTY but it was declared on public \Carbon\Carbon $birth_date which requires an attribute declared to support \Attribute::TARGET_PARAMETER

In PHP 8, this is functionally equivalent to

class FooData extends Spatie\LaravelData\Data {
    #[WithTransformer(DateTimeInterfaceTransformer::class)]
    public Carbon $birth_date;
    public function __construct(
        Carbon $birth_date
    ) {
         $this->birth_date = $birth_date;
    }

which does not report the error.

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

1 participant