Coding-standard: UnusedPrivateElementsSniff.UnusedMethod - false positive with Closure::fromCallable()

Created on 6 Dec 2017  路  4Comments  路  Source: slevomat/coding-standard

Closure::fromCallable is very useful when you want to pass a private method as callback. The sniff should recognize such method as used.

class Foo
{
    public function test()
    {
        array_map(\Closure::fromCallable([$this, 'map']), []);
    }

    private function map($item)
    {
        // ...
    }
}

Most helpful comment

If you prepare PR, I'm willing to merge it. However I don't want to invest my time for supporting the old way [$this, 'map'].

You should really rewrite the code in the example to:

array_map(function ($item) {
    return $this->map($item);
}, []);

All 4 comments

If you prepare PR, I'm willing to merge it. However I don't want to invest my time for supporting the old way [$this, 'map'].

You should really rewrite the code in the example to:

array_map(function ($item) {
    return $this->map($item);
}, []);

That's the syntax I used before. It's too much writing and forces you to repeat all the parameters. No thanks.

@enumag Yet it's cleaner for most IDEs, static analysis tools and refactoring tools

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings