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
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
<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:
- In a Laravel 9 project
- Create a file called
app\Policies\CustomerPolicy.phpwith the code sample above... - Run
phpcs app\Policies\CustomerPolicy.php ... - 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