Skip to content

Commit 3d248f8

Browse files
authored
Fix phpstan (#2685)
1 parent 41977f3 commit 3d248f8

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

.github/workflows/phpstan.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on:
55
paths:
66
- '**.php'
77
- 'phpstan.neon.dist'
8+
pull_request:
9+
paths:
10+
- '**.php'
11+
- 'phpstan.neon.dist'
812

913
jobs:
1014
phpstan:
@@ -16,7 +20,7 @@ jobs:
1620
- name: Setup PHP
1721
uses: shivammathur/setup-php@v2
1822
with:
19-
php-version: 8.1
23+
php-version: 8.3
2024
coverage: none
2125

2226
- name: Install composer dependencies

phpstan.neon.dist

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ parameters:
1111
- database/migrations/add_teams_fields.php.stub
1212
tmpDir: build/phpstan
1313
checkOctaneCompatibility: true
14-
checkMissingIterableValueType: false
1514

1615
ignoreErrors:
1716
- '#Unsafe usage of new static#'

src/Contracts/Permission.php

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* @property string|null $guard_name
1111
*
1212
* @mixin \Spatie\Permission\Models\Permission
13+
* @phpstan-require-extends \Spatie\Permission\Models\Permission
1314
*/
1415
interface Permission
1516
{

src/Contracts/Role.php

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* @property string|null $guard_name
1111
*
1212
* @mixin \Spatie\Permission\Models\Role
13+
* @phpstan-require-extends \Spatie\Permission\Models\Role
1314
*/
1415
interface Role
1516
{

src/Traits/HasRoles.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,14 @@ public function hasRole($roles, ?string $guard = null): bool
233233

234234
return $this->roles
235235
->when($guard, fn ($q) => $q->where('guard_name', $guard))
236-
->contains(function ($role) use ($roles) {
237-
if ($role->name instanceof \BackedEnum) {
238-
return $role->name->value == $roles;
236+
->pluck('name')
237+
->contains(function ($name) use ($roles) {
238+
/** @var string|\BackedEnum $name */
239+
if ($name instanceof \BackedEnum) {
240+
return $name->value == $roles;
239241
}
240242

241-
return $role->name == $roles;
243+
return $name == $roles;
242244
});
243245
}
244246

0 commit comments

Comments
 (0)