Larastan: Higher Order Proxy functions

Created on 7 Nov 2018  路  7Comments  路  Source: nunomaduro/larastan

  • Larastan Version: 0.3.8
  • default level used:

Description:

I am using the higher order proxy methods of collections, for example "map". The error message I get is: Access to an undefined property Illuminate\Support\HigherOrderCollectionProxy::$id.

Laravel code where the issue was found:

        return collect($room->getLights())->map(function (HueLight $hueLight) {
            return Light::whereExternalId($hueLight->getId())->first();
        })->map->id;
enhancement help wanted

Most helpful comment

@nmokkenstorm I'd prefer the functionality inside the Larastan. With proper implementation and tests. Feel free to make a PR :+1:

All 7 comments

Thanks for reporting this. We don't support Higher Order Proxy functions, yet.

Just to add another example, it's not only about attributes, also methods:

$post->attachments->map->getAttributes()->all();

yields

    Call to an undefined method
    Illuminate\Support\HigherOrderCollectionProxy::getAttributes().

Yes, I've seen this error message.

This can be solved by the PHPStan generics to some extent. But there would be some edge cases I think.

I would accept a PR that adds a support for this :+1:

I would accept a PR that adds a support for this 馃憤

I created a plugin that fixes this, and extracted it to a package over here today. Do I clean up the package and add it as a dependency, or is porting the code directly to this repository preferable?

@nmokkenstorm I'd prefer the functionality inside the Larastan. With proper implementation and tests. Feel free to make a PR :+1:

I would gladly see @nmokkenstorm's extension in Larastan 鉂わ笍

Was this page helpful?
0 / 5 - 0 ratings