Squiz.Commenting.FunctionComment.IncorrectTypeHint don't recognize namespace aliases

Author: FrittenKeeZCreated Aug 15, 2022Updated Mar 5, 2026
LabelsType: bugStandard: PEARStandard: SquizFocus: Comments/Docblocks

Describe the bug Using namespace alises (imports) the rule thinks a wrong type hint is used.

Code sample

php
<?php

namespace App\Policies;

use Illuminate\Auth\Access\HandlesAuthorization;
use Illuminate\Contracts\Auth\Authenticatable as User;

class CustomerPolicy
{
    use HandlesAuthorization;

    /**
     * Determine whether the user can view any models.
     *
     * @param \Illuminate\Contracts\Auth\Authenticatable $user
     *
     * @return mixed
     */
    public function viewAny(User $user)
    {
        return true;
    }

Custom ruleset

xml
<rule ref="PSR12">
    <exclude name="Squiz.Commenting.FunctionComment.IncorrectParamVarName" />
    <exclude name="Squiz.Commenting.FunctionComment.InvalidReturn" />
    <exclude name="Squiz.Commenting.FunctionComment.MissingParamComment" />
    <exclude name="PEAR.Commenting.FunctionComment.MissingParamComment" />
</rule>
<rule ref="Squiz.Commenting.FunctionComment.TypeHintMissing">
    <exclude-pattern>*/app/Http/Middleware/*</exclude-pattern>
    <exclude-pattern>*/app/Http/Resources/*</exclude-pattern>
    <exclude-pattern>*/app/Nova/*</exclude-pattern>
</rule>

To reproduce Steps to reproduce the behavior:

  1. In a Laravel 9 project
  2. Create a file called app\Policies\CustomerPolicy.php with the code sample above...
  3. Run phpcs app\Policies\CustomerPolicy.php ...
  4. See error message displayed
Expected type hint "\Illuminate\Contracts\Auth\Authenticatable"; found "User" for $user (Squiz.Commenting.FunctionComment.IncorrectTypeHint)

Expected behavior The aliased namespace should correctly be detected and no error given.

Versions (please complete the following information):

  • OS: 12.5
  • PHP: 8.0
  • PHPCS: .9.5
  • Standard: PSR12

Source: squizlabs/PHP_CodeSniffer