laravel-ide-helper
laravel-ide-helper copied to clipboard
New format computed property accessor not recognised
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).
We're open to PRs \o/
are there any progress/PR on this?
If you make the function public, and provide a return type like so: fn(): string
, it works.
That's true, but then it's no longer an accessor/mutator, which is the topic of this issue.
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?
does it matter though using public/protected
?
does it matter though using
public/protected
?
The Laravel docs makes them protected
. But ide-helper only picks them up when they are public
.
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.
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.
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
I have given up on waiting for this and have stopped using this package in favour of the Laravel IDEA plugin.
A new version was released an hour ago; https://github.com/barryvdh/laravel-ide-helper/releases/tag/v2.14.0