laravel-ide-helper icon indicating copy to clipboard operation
laravel-ide-helper copied to clipboard

New format computed property accessor not recognised

Open pindab0ter opened this issue 2 years ago • 12 comments

Versions:

  • ide-helper Version: 2.12.2
  • Laravel Version: 9.0.0
  • PHP Version: 8.1.2

Description:

PR #1289 added support for the new attribute mutator/accessor format, but calculated properties/attributes aren't recognised yet.

Steps To Reproduce:

This example calculated property results in * @property-read string $full_name:

public function getFullNameAttribute(): string
{
    return "$this->first_name $this->last_name";
}

The following example is not recognised and does not add the same @property.

public function fullName(): Attribute
{
    return Attribute::get(fn() => "$this->first_name $this->last_name");
}

~~It should also result in (only) $fullName instead of $full_name.~~

The latter should also be protected instead of public of course, but that's a separate issue (#1293).

pindab0ter avatar Feb 10 '22 12:02 pindab0ter

We're open to PRs \o/

mfn avatar Feb 10 '22 13:02 mfn

are there any progress/PR on this?

sawirricardo avatar Apr 05 '22 10:04 sawirricardo

If you make the function public, and provide a return type like so: fn(): string, it works.

john-inkesta avatar Aug 22 '23 13:08 john-inkesta

That's true, but then it's no longer an accessor/mutator, which is the topic of this issue.

pindab0ter avatar Aug 22 '23 14:08 pindab0ter

What I mean is, if you do this:

public function fullName(): Attribute
{
    return Attribute::get(fn(): string => "$this->first_name $this->last_name");
}

It will generate a full_name property for you.

That's all you want, isn't it?

john-inkesta avatar Aug 22 '23 14:08 john-inkesta

does it matter though using public/protected?

sawirricardo avatar Aug 22 '23 14:08 sawirricardo

does it matter though using public/protected?

The Laravel docs makes them protected. But ide-helper only picks them up when they are public.

john-inkesta avatar Aug 23 '23 06:08 john-inkesta

The Laravel docs makes them protected. But ide-helper only picks them up when they are public.

The PR was merged https://github.com/barryvdh/laravel-ide-helper/pull/1339 but there has been no release after that.

You can try the dev-master version I guess.

mfn avatar Aug 23 '23 07:08 mfn

What I mean is, if you do this:


public function fullName(): Attribute

{

    return Attribute::get(fn(): string => "$this->first_name $this->last_name");

}

It will generate a full_name property for you.

That's all you want, isn't it?

True. That's what I do nowadays. That said, Laravel supports accessors without typehinting whereas IDE Helper doesn't.

Hence my PR #1411.

pindab0ter avatar Aug 24 '23 08:08 pindab0ter

Any idea when this will be released on packagist? I'd prefer not to directly require dev-master, but this does work great for our use case. @barryvdh

TzviPM avatar Oct 17 '23 14:10 TzviPM

I have given up on waiting for this and have stopped using this package in favour of the Laravel IDEA plugin.

pindab0ter avatar Feb 05 '24 10:02 pindab0ter

A new version was released an hour ago; https://github.com/barryvdh/laravel-ide-helper/releases/tag/v2.14.0

barryvdh avatar Feb 05 '24 12:02 barryvdh