/**
 * Function comment.
 *
 * @param \stdClass $object
 *   Parameter description.
 */
function function_name(\stdClass $object) {

This code doesn't trigger any issues. Only if stdClass is used instead of \stdClass.
I think this should be improved so that we also get an error for \stdClass too.

Comments

mfernea created an issue. See original summary.

andypost’s picture

btw It could lead to false positives when function really defines argument as \stdClass

mile23’s picture

Title: Commenting.FunctionComment - \stdClass » Drupal.Commenting.FunctionComment.InvalidTypeHint/FunctionComment - \stdClass
Related issues: +#2723621: Fix Drupal.Commenting.FunctionComment.IncorrectTypeHint and Drupal.Commenting.FunctionComment.InvalidTypeHint

This should be allowed:

/**
 * @param object $name
 */
function foo(\stdClass $name) {}

...since \stdClass is a valid type hint.

It's an almost useless type hint, but it's valid. :-)

Also, in .inc files, InvalidTypeHint gives a pass to stdClass as a hint, but not \stdClass. See #2723621-37: Fix Drupal.Commenting.FunctionComment.IncorrectTypeHint and Drupal.Commenting.FunctionComment.InvalidTypeHint

idebr’s picture

Version: 8.x-2.x-dev » 8.x-3.x-dev

  • klausi committed a7c2146 on 8.x-3.x
    fix(FunctionComment): Detect \stdClass type hint correctly (#2911404)
    
klausi’s picture

Status: Active » Fixed

Committed a fix for this, thanks for reporting!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.