Skip to content

Commit

Permalink
Use union types on contracts and models
Browse files Browse the repository at this point in the history
  • Loading branch information
drbyte committed Aug 21, 2023
1 parent bd01bee commit 05372f9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/Contracts/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function roles(): BelongsToMany;
/**
* Find a permission by its name.
*
* @return \Spatie\Permission\Contracts\Permission
*
* @throws \Spatie\Permission\Exceptions\PermissionDoesNotExist
*/
Expand All @@ -29,14 +30,17 @@ public static function findByName(string $name, ?string $guardName): self;
/**
* Find a permission by its id.
*
* @param int|string $id
* @return \Spatie\Permission\Contracts\Permission
*
* @throws \Spatie\Permission\Exceptions\PermissionDoesNotExist
*/
public static function findById($id, ?string $guardName): self;
public static function findById(int|string $id, ?string $guardName): self;

/**
* Find or Create a permission by its name and guard name.
*
* @return \Spatie\Permission\Contracts\Permission
*
*/
public static function findOrCreate(string $name, ?string $guardName): self;
}
3 changes: 1 addition & 2 deletions src/Contracts/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ public static function findByName(string $name, ?string $guardName): self;
/**
* Find a role by its id and guard name.
*
* @param int|string $id
* @return \Spatie\Permission\Contracts\Role
*
* @throws \Spatie\Permission\Exceptions\RoleDoesNotExist
*/
public static function findById($id, ?string $guardName): self;
public static function findById(int|string $id, ?string $guardName): self;

/**
* Find or create a role by its name and guard name.
Expand Down
3 changes: 1 addition & 2 deletions src/Models/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,11 @@ public static function findByName(string $name, string $guardName = null): Permi
/**
* Find a permission by its id (and optionally guardName).
*
* @param int|string $id
* @return PermissionContract|Permission
*
* @throws PermissionDoesNotExist
*/
public static function findById($id, string $guardName = null): PermissionContract
public static function findById(int|string $id, string $guardName = null): PermissionContract
{
$guardName = $guardName ?? Guard::getDefaultName(static::class);
$permission = static::getPermission([(new static())->getKeyName() => $id, 'guard_name' => $guardName]);
Expand Down
3 changes: 1 addition & 2 deletions src/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,9 @@ public static function findByName(string $name, string $guardName = null): RoleC
/**
* Find a role by its id (and optionally guardName).
*
* @param int|string $id
* @return RoleContract|Role
*/
public static function findById($id, string $guardName = null): RoleContract
public static function findById(int|string $id, string $guardName = null): RoleContract
{
$guardName = $guardName ?? Guard::getDefaultName(static::class);

Expand Down

0 comments on commit 05372f9

Please sign in to comment.