Skip to content

Commit

Permalink
fix: phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
yajra committed Aug 6, 2024
1 parent f21cca1 commit 26090c3
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
2 changes: 0 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ parameters:
ignoreErrors:

excludePaths:

checkMissingIterableValueType: true
17 changes: 9 additions & 8 deletions src/GateRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,33 @@ public function register(): void

/**
* Get all permissions.
*
* @return \Illuminate\Support\Collection<array-key, Permission>
*/
protected function getPermissions(): Collection
{
/** @var string $key */
$key = config('acl.cache.key', 'permissions.policies');

try {
$permissions = config('acl.cache.enabled', true)
return config('acl.cache.enabled', true)
? $this->cache->rememberForever($key, fn () => $this->getPermissionsFromQuery())
: $this->getPermissionsFromQuery();

return collect($permissions)->map(fn ($data) => new Permission($data));
} catch (\Throwable) {
$this->cache->forget($key);

return collect([]);
return collect();
}
}

public function getPermissionsFromQuery(): array
/**
* @return \Illuminate\Support\Collection<array-key, Permission>
*/
public function getPermissionsFromQuery(): Collection
{
// @phpstan-ignore-next-line
return $this->getPermissionClass()
->with('roles')
->get()
->toArray();
->get();
}

protected function getPermissionClass(): Permission
Expand Down
1 change: 1 addition & 0 deletions src/Models/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public function users(): BelongsToMany
/** @var class-string<\Illuminate\Foundation\Auth\User> $model */
$model = config('acl.user', config('auth.providers.users.model'));

// @phpstan-ignore-next-line
return $this->belongsToMany($model)->withTimestamps();
}
}
1 change: 1 addition & 0 deletions src/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function users(): BelongsToMany
/** @var class-string<\Illuminate\Foundation\Auth\User> $model */
$model = config('acl.user', config('auth.providers.users.model'));

// @phpstan-ignore-next-line
return $this->belongsToMany($model)->withTimestamps();
}
}
3 changes: 2 additions & 1 deletion src/Traits/InteractsWithPermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ public function grantPermission(mixed $ids, array $attributes = [], bool $touch
*/
public function permissions(): BelongsToMany
{
/** @var class-string $model */
/** @var class-string<Permission> $model */
$model = config('acl.permission', Permission::class);

// @phpstan-ignore-next-line
return $this->belongsToMany($model)->withTimestamps();
}

Expand Down
3 changes: 2 additions & 1 deletion src/Traits/InteractsWithRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ public function attachRole(mixed $role, array $attributes = [], bool $touch = tr
*/
public function roles(): BelongsToMany
{
/** @var class-string $model */
/** @var class-string<Role> $model */
$model = config('acl.role', Role::class);

// @phpstan-ignore-next-line
return $this->belongsToMany($model)->withTimestamps();
}

Expand Down

0 comments on commit 26090c3

Please sign in to comment.