djoos / Symfony-coding-standard

Development repository for the Symfony coding standard
MIT License
401 stars 102 forks source link

Typehinting enclosures detects returntype wrongly #134

Closed raalderink closed 6 years ago

raalderink commented 6 years ago

The sniff Symfony.Functions.ReturnType.Invalid detects enclosures wrongly.

I have a function like this:

function test(array &$a): void
{
    foreach ($a as &$b) {
        usort(
            $b,
            function ($c, $d): int {
                return (int)$c['sort'] <=> (int)$d['sort'];
            }
        );
    }
}

The function's returntype is void, but the closure's returntype is int. However, the sniff fails on the closure's return line, with the following message: "Use return null; when a function explicitlyreturns null values and use return; when the function returns void values"

tifabien commented 6 years ago

I have the same issue. You can temporarly add /* @codingStandardsIgnoreLine */ just above your return (int)$c['sort'] <=> (int)$d['sort'];

djoos commented 6 years ago

Closing this issue - fixed in #141

tifabien commented 6 years ago

Great news! Thanks a lot!