Commit a7c21460 authored by Klaus Purer's avatar Klaus Purer
Browse files

fix(FunctionComment): Detect \stdClass type hint correctly (#2911404)

parent 3618dc9a
Loading
Loading
Loading
Loading
+19 −18
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ class FunctionCommentSniff implements Sniff
        'integer'   => 'int',
        'str'       => 'string',
        'stdClass'  => 'object',
        '\stdClass' => 'object',
        'number'    => 'int',
        'String'    => 'string',
        'type'      => 'mixed',
@@ -734,7 +735,7 @@ class FunctionCommentSniff implements Sniff
                    && isset($realParams[$checkPos]) === true
                ) {
                    $typeHint = $realParams[$checkPos]['type_hint'];
                    if ($typeHint !== '' && $typeHint !== 'stdClass') {
                    if ($typeHint !== '' && $typeHint !== 'stdClass' && $typeHint !== '\stdClass') {
                        $error = 'Unknown type hint "%s" found for %s';
                        $data  = [
                            $typeHint,
+12 −0
Original line number Diff line number Diff line
@@ -441,3 +441,15 @@ function test34($a, $b) {
    yield $i;
  }
}

/**
 * Using \stdClass as type hint is ok, but not in the documentation.
 *
 * @param object $name
 *   Some description.
 * @param \stdClass $param2
 *   Some description.
 */
function test35(\stdClass $name, \stdClass $param2) {

}
+13 −1
Original line number Diff line number Diff line
@@ -383,7 +383,7 @@ class Test2 extends AbstractTest {
  /**
   * Run method with missing described variable.
   *
   * @param \stdClass $start
   * @param object $start
   *   Start point.
   *
   * @return bool
@@ -467,3 +467,15 @@ function test34($a, $b) {
    yield $i;
  }
}

/**
 * Using \stdClass as type hint is ok, but not in the documentation.
 *
 * @param object $name
 *   Some description.
 * @param object $param2
 *   Some description.
 */
function test35(\stdClass $name, \stdClass $param2) {

}
+2 −0
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ class FunctionCommentUnitTest extends CoderSniffUnitTest
                357 => 1,
                360 => 1,
                371 => 1,
                374 => 1,
                389 => 2,
                390 => 2,
                401 => 1,
@@ -71,6 +72,7 @@ class FunctionCommentUnitTest extends CoderSniffUnitTest
                416 => 1,
                426 => 2,
                427 => 2,
                450 => 1,
            ];
        case 'FunctionCommentUnitTest.1.inc':
            return [];