Php_codesniffer: Squiz.Commenting.FunctionComment false positive when function contains closure

Created on 8 Jul 2017  路  6Comments  路  Source: squizlabs/PHP_CodeSniffer

There is a false positive in src\Standards\Squiz\Sniffs\Commenting\FunctionCommentSniff.php

This code throws error: Function return type is not void, but function is returning void here

/**
 * Test function
 *
 * @return array
 */
public function test()
{
    function () {
        return;
    };

    return [];
}
Bug

Most helpful comment

The same issue we have also in case:

function test()
{
    new class() {
        public function test() {
            return;
        }
    };

    return [];
}

@josephzidell Here is my PR with fix for both cases: #1551

All 6 comments

The same issue we have also in case:

function test()
{
    new class() {
        public function test() {
            return;
        }
    };

    return [];
}

@josephzidell Here is my PR with fix for both cases: #1551

Thanks for coming up with a fix so quickly

@webimpress Found another, related issue

Code:

/**
 * Test function
 *
 * @return void
 */
public function test()
{
    function () {
        return 4;
    };
}

Error: Function return type is void, but function contains return statement

:+1:

This has now been fixed. Thanks a lot for reporting this.

Was this page helpful?
0 / 5 - 0 ratings