Phpinspectionsea: "The closure can be replaced with ..." suggests replacing with wrong value

Created on 27 Jul 2020  路  6Comments  路  Source: kalessil/phpinspectionsea

| Subject | Details |
| :------------- | :---------------------------------------------------------------------------- |
| Plugin | Php Inspections (EA Ultimate) |
| Language level | PHP 7.4 |

Current behaviour

EA suggests replacing the closure fn ($id) => Document::getById($id) inside an array_map() with just 'getById'.

Suggestion:
grafik

Applied suggestion:
grafik

This is obviously wrong.

Expected behaviour

It suggests replacing the closure with [Document::class, 'getById'] instead.

Environment details

PhpStorm 2020.1.4
Build #PS-201.8743.18, built on July 22, 2020
Runtime version: 11.0.7+10-b765.65 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 4.15.0-112-generic

bug / false-positive

Most helpful comment

Fixed!

All 6 comments

Oops, thank you for reporting @jdreesen, I'll take care of fixing this.

@jdreesen, one question here.

It was intended to work with functions only, so I'm wondering if we should handle methods references at all.
What do you think?

Well, I somehow like to use the array form ([Document::class, 'getById']) instead of closures (fn ($id) => Document::getById($id)) when possible.

But with PHP 7.4 and short closures I'd be totally fine if EA doesn't support this.

After all, closures have advantages over arrays, as they're more explicit (especially with multiple arguments).

Uh, happy to hear that. I also prefer using short closures in this specific case.

Well, I actually like using the short closures everywhere =)

Fixed!

Was this page helpful?
0 / 5 - 0 ratings