Commit 070c7279 authored by Peter Wolanin's avatar Peter Wolanin Committed by Klaus Purer
Browse files

fix(FunctionComment): Allow object as a function param typehint (#3059698 by pwolanin, klausi)

parent 9ac24f25
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -762,7 +762,12 @@ class FunctionCommentSniff implements Sniff
                    && isset($realParams[$checkPos]) === true
                ) {
                    $typeHint = $realParams[$checkPos]['type_hint'];
                    if ($typeHint !== '' && $typeHint !== 'stdClass' && $typeHint !== '\stdClass') {
                    if ($typeHint !== ''
                        && $typeHint !== 'stdClass'
                        && $typeHint !== '\stdClass'
                        // As of PHP 7.2, object is a valid type hint.
                        && $typeHint !== 'object'
                    ) {
                        $error = 'Unknown type hint "%s" found for %s';
                        $data  = [
                            $typeHint,
+12 −0
Original line number Diff line number Diff line
@@ -453,3 +453,15 @@ function test34($a, $b) {
function test35(\stdClass $name, \stdClass $param2) {

}

/**
 * Allow "object" as real type hint (PHP 7.2).
 *
 * @param \stdClass $arg
 *   Something here.
 * @param object $blarg
 *   Another thing.
 */
function test36(object $arg, object $blarg) {
  return $arg;
}
+12 −0
Original line number Diff line number Diff line
@@ -479,3 +479,15 @@ function test34($a, $b) {
function test35(\stdClass $name, \stdClass $param2) {

}

/**
 * Allow "object" as real type hint (PHP 7.2).
 *
 * @param object $arg
 *   Something here.
 * @param object $blarg
 *   Another thing.
 */
function test36(object $arg, object $blarg) {
  return $arg;
}
+1 −0
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ class FunctionCommentUnitTest extends CoderSniffUnitTest
                426 => 2,
                427 => 2,
                450 => 1,
                460 => 1,
            ];
        case 'FunctionCommentUnitTest.1.inc':
            return [];