Skip to content

Commit

Permalink
Fix phpstan (#2685)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikn69 authored Jun 21, 2024
1 parent 41977f3 commit 3d248f8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
paths:
- '**.php'
- 'phpstan.neon.dist'
pull_request:
paths:
- '**.php'
- 'phpstan.neon.dist'

jobs:
phpstan:
Expand All @@ -16,7 +20,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.3
coverage: none

- name: Install composer dependencies
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ parameters:
- database/migrations/add_teams_fields.php.stub
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkMissingIterableValueType: false

ignoreErrors:
- '#Unsafe usage of new static#'
Expand Down
1 change: 1 addition & 0 deletions src/Contracts/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @property string|null $guard_name
*
* @mixin \Spatie\Permission\Models\Permission
* @phpstan-require-extends \Spatie\Permission\Models\Permission
*/
interface Permission
{
Expand Down
1 change: 1 addition & 0 deletions src/Contracts/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @property string|null $guard_name
*
* @mixin \Spatie\Permission\Models\Role
* @phpstan-require-extends \Spatie\Permission\Models\Role
*/
interface Role
{
Expand Down
10 changes: 6 additions & 4 deletions src/Traits/HasRoles.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,14 @@ public function hasRole($roles, ?string $guard = null): bool

return $this->roles
->when($guard, fn ($q) => $q->where('guard_name', $guard))
->contains(function ($role) use ($roles) {
if ($role->name instanceof \BackedEnum) {
return $role->name->value == $roles;
->pluck('name')
->contains(function ($name) use ($roles) {
/** @var string|\BackedEnum $name */
if ($name instanceof \BackedEnum) {
return $name->value == $roles;
}

return $role->name == $roles;
return $name == $roles;
});
}

Expand Down

0 comments on commit 3d248f8

Please sign in to comment.