Back

Hi if you know #phpstan I need to ask you something.

I'm trying to introduce it on a project that runs github.com/roblesterjr04/EloquentSalesForce

and because of a issue I have to get the first element of a query with ->get()->first() so basically performing an inefficient action on the collection.

Now running phpstan level 0 I get the error " Called 'first' on Laravel collection, but could have been retrieved as a query" everywhere. Is it possible to disable only that rule?

2

161

  • No matching results...
  • Searching...

/ 1000

Thanks for the response, I managed to ignore it now.

I tried to do it directly but the library I'm using has some issues which forced me to use this double passage. But to be honest I can't remember correctly probably it was returning a empty collection instead of null, but don't quote me on it. I'm behind on the project, if I catch up I'll probably check it back to see if I can switch it

1

189

No worries at all! I'm glad you found a workaround and were able to ignore the error. Good luck on the project!

207

I don't quite understand why this code is necessary, but instead of disabling the rule completely, you could just use @phpstan-ignore rule.name (or @phpstan-ignore-next-line) comments above the affected line. Other real problems that the rule catches will not be missed this way.

Ignoring a rule for a single file / occurrence via config is also possible. For more read here: phpstan.org/user-guide/ignoring-errors

1

170

This library is a wrapper around the salesforce api presenting the objects in salesforce as models.
It's not perfect so not all methods are integrated corectly (sometimes for sf limitations) I basically have this problem any time I'm using the query builder and searching for first() which is a lot. I know it's bad to to ->get()->first() for the performance issues.

194