Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v7] Update Role contract to match implementation and fix PhpStan errors #2676

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

SanderMuller
Copy link
Contributor

Allow BackedEnum and set default guardName

Fixes the following PhpStan error:

 ------ -------------------------------------------------------------------- 
  Line   app/Console/Commands/EnsureRolesAndPermissionsAreSetCommand.php     
 ------ -------------------------------------------------------------------- 
  29     Method Spatie\Permission\Contracts\Role::hasPermissionTo() invoked  
         with 1 parameter, 2 required.                                       
         ✏️  app/Console/Commands/EnsureRolesAndPermissionsAreSetCommand.php  
  29     Parameter #1 $permission of method                                  
         Spatie\Permission\Contracts\Role::hasPermissionTo() expects         
         Spatie\Permission\Contracts\Permission|string,                      
         App\Enums\Permissions\PermissionEnum::LOGIN_AS_ANY given.           
         ✏️  app/Console/Commands/EnsureRolesAndPermissionsAreSetCommand.php  
 ------ -------------------------------------------------------------------- 

caused by this line in my application:
$role->hasPermissionTo(PermissionEnum::LOGIN_AS_ANY)

I am passing an enum instance which is allowed according to the docs, and works, but the interface Docblock does not support this. The other error says I am required to pass two parameters, while the second param ($guardName) is optional according to the implementations, but not according to the interface

Allow BackedEnum and set default guardName
@drbyte
Copy link
Collaborator

drbyte commented Jun 22, 2024

I agree with your point.
It may be a breaking change for many though.
So may have to hold off on this for awhile.

@SanderMuller
Copy link
Contributor Author

I agree with your point. It may be a breaking change for many though. So may have to hold off on this for awhile.

Maybe we can just update the dockblocks as a patch and then the actual types in a major version?

@drbyte
Copy link
Collaborator

drbyte commented Jun 22, 2024

Yes, that'd be fine.

@drbyte
Copy link
Collaborator

drbyte commented Jun 22, 2024

Added BackedEnum in 59b966f

@SanderMuller SanderMuller changed the title Update Role contract to match implementation and fix PhpStan errors [v7] Update Role contract to match implementation and fix PhpStan errors Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants