Fatal error : Declaration of App\Policy\UsersTablePolicy::beforeScope(Authorization\IdentityInterface $user, Cake\Database\Query $query, string $action): Cake\Database\Query must be compatible with Authorization\Policy\BeforeScopeInterface::beforeScope(?Authorization\IdentityInterface $identity, mixed $resource, string $action): mixed in
Change your type hinting to match the BeforeScopeInterface in vendor/cakephp/authorization/src/Policy/BeforeScopeInterface.php
The interface definition:
public function beforeScope(?IdentityInterface $identity, mixed $resource, string $action): mixed;
i.e.
beforeScope(IdentityInterface $user, mixed $resource, string $action): mixed
{
if ($user->getOriginalData()->is_trial_user) {
return $query->where(['Articles.is_paid_only' => false]);
}
}
mixed $query
is what you might want to use.
You can still annotate it as real query in the docblock above. This way you have autocomplete and PHPStorm also knows what this class is inside.
1 Like