From c0389145a4c0596f01dfdb510038c81b68bbb019 Mon Sep 17 00:00:00 2001 From: Warrick Bayman Date: Sat, 6 Jan 2024 16:05:54 +0200 Subject: [PATCH] Apply fixes from StyleCI (#28) --- src/Contracts/DeadboltServiceInterface.php | 6 ++--- src/Contracts/UserCollectionInterface.php | 12 ++++----- src/Contracts/UserInterface.php | 18 ++++++++----- src/DeadboltService.php | 4 +-- src/DeadboltServiceProvider.php | 2 +- src/Exceptions/NoSuchPermissionException.php | 2 +- src/User.php | 28 +++++++++++--------- src/UserCollection.php | 14 +++++----- tests/Models/Role.php | 1 - tests/Models/User.php | 1 - tests/factories/UserFactory.php | 1 - 11 files changed, 47 insertions(+), 42 deletions(-) diff --git a/src/Contracts/DeadboltServiceInterface.php b/src/Contracts/DeadboltServiceInterface.php index 5857391..29709e2 100644 --- a/src/Contracts/DeadboltServiceInterface.php +++ b/src/Contracts/DeadboltServiceInterface.php @@ -12,7 +12,7 @@ interface DeadboltServiceInterface { /** - * @param array $config + * @param array $config */ public function __construct(array $config); @@ -24,7 +24,7 @@ public function user(Model $model): User; /** * A collection of users to manipulate permissions for. * * - * @param array $users + * @param array $users */ public function users(...$users): UserCollection; @@ -41,7 +41,7 @@ public function all(): array; /** * Get the permission descriptions. * - * @param array $permissions + * @param array $permissions */ public function describe(...$permissions): array; } diff --git a/src/Contracts/UserCollectionInterface.php b/src/Contracts/UserCollectionInterface.php index 88c6e11..f2f63c1 100644 --- a/src/Contracts/UserCollectionInterface.php +++ b/src/Contracts/UserCollectionInterface.php @@ -16,7 +16,7 @@ public function __construct(array $users, array $permissions, array $config); /** * Give the specified permissions to the user collection. * - * @param array $names + * @param array $names */ public function give(...$names): UserCollectionInterface; @@ -28,7 +28,7 @@ public function super(): UserCollectionInterface; /** * Revoke the specified permissions from the user collection. * - * @param array $names + * @param array $names */ public function revoke(...$names): UserCollectionInterface; @@ -40,7 +40,7 @@ public function revokeAll(): UserCollectionInterface; /** * Sync the specified permissions with the user collection. * - * @param array $names + * @param array $names */ public function sync(...$names): UserCollectionInterface; @@ -52,14 +52,14 @@ public function save(): UserCollectionInterface; /** * Check if all the users have all the specified permissions. * - * @param array $permissions + * @param array $permissions */ public function allHave(...$permissions): bool; /** * Check if all the users have at least one of the specified permissions. * - * @param array $permissions + * @param array $permissions */ public function anyHave(...$permissions): bool; @@ -71,7 +71,7 @@ public function has(string $permission): bool; /** * Check if all the users have none of the specified permissions. * - * @param array $permissions + * @param array $permissions */ public function noneHave(...$permissions): bool; } diff --git a/src/Contracts/UserInterface.php b/src/Contracts/UserInterface.php index 44e8180..6f0eb93 100644 --- a/src/Contracts/UserInterface.php +++ b/src/Contracts/UserInterface.php @@ -16,7 +16,7 @@ public function __construct(Model $user, array $permissions, array $config); /** * Give the specified permissions. * - * @param array|string ...$names + * @param array|string ...$names * @return UserInterface * * @throws JsonException|NoSuchPermissionException @@ -38,7 +38,7 @@ public function isSuper(): bool; /** * Revoke the specified permissions. * - * @param array|string $names + * @param array|string $names * * @throws JsonException */ @@ -52,7 +52,7 @@ public function revokeAll(): UserInterface; /** * Sync permissions with the names provided. * - * @param array|string ...$names + * @param array|string ...$names */ public function sync(...$names): UserInterface; @@ -62,7 +62,8 @@ public function sync(...$names): UserInterface; public function save(): UserInterface; /** - * Check if the specified permission is assigned.* + * Check if the specified permission is assigned.*. + * * @throws JsonException */ public function has(string $permission): bool; @@ -70,7 +71,8 @@ public function has(string $permission): bool; /** * Check if all the specified permissions are assigned. * - * @param array|string $permissions + * @param array|string $permissions + * * @throws JsonException */ public function hasAll(...$permissions): bool; @@ -78,7 +80,8 @@ public function hasAll(...$permissions): bool; /** * Check if any of the specified permissions are assigned. * - * @param array|string $permissions + * @param array|string $permissions + * * @throws JsonException */ public function hasAny(...$permissions): bool; @@ -86,7 +89,8 @@ public function hasAny(...$permissions): bool; /** * Check if none of the specified permissions are assigned. * - * @param array|string ...$permissions + * @param array|string ...$permissions + * * @throws JsonException */ public function hasNone(...$permissions): bool; diff --git a/src/DeadboltService.php b/src/DeadboltService.php index 289acb0..13b0c04 100644 --- a/src/DeadboltService.php +++ b/src/DeadboltService.php @@ -39,7 +39,7 @@ public function user(Model $model): User /** * A collection of users to manipulate permissions for. * - * @param array $users + * @param array $users */ public function users(...$users): UserCollection { @@ -67,7 +67,7 @@ public function all(): array /** * Get the permission descriptions. * - * @param array $permissions + * @param array $permissions */ public function describe(...$permissions): array { diff --git a/src/DeadboltServiceProvider.php b/src/DeadboltServiceProvider.php index bbdca39..ac7e780 100644 --- a/src/DeadboltServiceProvider.php +++ b/src/DeadboltServiceProvider.php @@ -44,7 +44,7 @@ protected function getMigrationFilename(string $migrationName): string { $timestamp = date('Y_m_d_His'); - return (string)collect(glob($this->app->databasePath().'/migrations/*'.$migrationName.'.php')) + return (string) collect(glob($this->app->databasePath().'/migrations/*'.$migrationName.'.php')) ->push($this->app->databasePath().'/migrations/'.$timestamp.'_'.$migrationName.'.php') ->first(); } diff --git a/src/Exceptions/NoSuchPermissionException.php b/src/Exceptions/NoSuchPermissionException.php index b5605dd..3263e7b 100644 --- a/src/Exceptions/NoSuchPermissionException.php +++ b/src/Exceptions/NoSuchPermissionException.php @@ -10,7 +10,7 @@ class NoSuchPermissionException extends Exception { public function __construct(string $permission) { - $message = 'The permission ' . $permission . ' does not exist'; + $message = 'The permission '.$permission.' does not exist'; parent::__construct($message, 1); } } diff --git a/src/User.php b/src/User.php index d03c291..ff6d3a4 100644 --- a/src/User.php +++ b/src/User.php @@ -20,7 +20,7 @@ public function __construct(protected Model $user, protected array $permissions, /** * Give the specified permissions. * - * @param array|string $names + * @param array|string $names * @return UserInterface * * @throws JsonException|NoSuchPermissionException @@ -43,13 +43,13 @@ protected function assignPermissions(array $permissions): UserInterface { $this->user->{$this->config['column']} = $this->permissionsAreCast() ? $permissions - : json_encode($permissions,JSON_THROW_ON_ERROR); + : json_encode($permissions, JSON_THROW_ON_ERROR); return $this->save(); } /** - * Check if the "permissions" field has already been cast on the model + * Check if the "permissions" field has already been cast on the model. */ protected function permissionsAreCast(): bool { @@ -81,7 +81,7 @@ public function isSuper(): bool /** * Revoke the specified permissions. * - * @param array|string ...$names + * @param array|string ...$names * @return UserInterface * * @throws JsonException|NoSuchPermissionException @@ -108,7 +108,8 @@ public function revokeAll(): UserInterface /** * Sync permissions with the names provided. * - * @param array|string $names + * @param array|string $names + * * @throws JsonException * @throws NoSuchPermissionException */ @@ -132,7 +133,7 @@ public function save(): UserInterface */ protected function findPermissionOrFail(string $permission): bool { - if (!$this->isPermission($permission)) { + if (! $this->isPermission($permission)) { throw new NoSuchPermissionException($permission); } @@ -147,7 +148,7 @@ protected function isPermission(string $name): bool /** * Check if the specified permission is assigned. * - * @param string $permission + * @param string $permission * @return bool * * @throws JsonException @@ -173,13 +174,14 @@ protected function userPermissions(): array /** * Check if all the specified permissions are assigned. * - * @param array|string $permissions + * @param array|string $permissions + * * @throws JsonException */ public function hasAll(...$permissions): bool { foreach (Arr::flatten($permissions) as $permission) { - if (!in_array($permission, $this->userPermissions(), true)) { + if (! in_array($permission, $this->userPermissions(), true)) { return false; } } @@ -190,7 +192,8 @@ public function hasAll(...$permissions): bool /** * Check if any of the specified permissions are assigned. * - * @param array|string ...$permissions + * @param array|string ...$permissions + * * @throws JsonException */ public function hasAny(...$permissions): bool @@ -207,12 +210,13 @@ public function hasAny(...$permissions): bool /** * Check if none of the specified permissions are assigned. * - * @param array|string $permissions + * @param array|string $permissions + * * @throws JsonException */ public function hasNone(...$permissions): bool { - return !$this->hasAny($permissions); + return ! $this->hasAny($permissions); } /** diff --git a/src/UserCollection.php b/src/UserCollection.php index 1a5a345..09dd43d 100644 --- a/src/UserCollection.php +++ b/src/UserCollection.php @@ -26,7 +26,7 @@ public function __construct(array $users, array $permissions, array $config) /** * Give the specified permissions to the user collection. * - * @param array $names + * @param array $names */ public function give(...$names): UserCollectionInterface { @@ -48,7 +48,7 @@ public function super(): UserCollectionInterface /** * Revoke the specified permissions from the user collection. * - * @param array $names + * @param array $names * @return UserCollectionInterface */ public function revoke(...$names): UserCollectionInterface @@ -71,7 +71,7 @@ public function revokeAll(): UserCollectionInterface /** * Sync the specified permissions with the user collection. * - * @param array $names + * @param array $names * @return UserCollectionInterface */ public function sync(...$names): UserCollectionInterface @@ -103,12 +103,12 @@ protected function callOnEachUser(string $name, mixed $arguments = null): UserCo /** * Check if all the users have the specified permissions. * - * @param array $permissions + * @param array $permissions */ public function allHave(...$permissions): bool { foreach ($this->users as $user) { - if (!$user->hasAll($permissions)) { + if (! $user->hasAll($permissions)) { return false; } } @@ -119,7 +119,7 @@ public function allHave(...$permissions): bool /** * Check if any of the users have all the specified permissions. * - * @param array $permissions + * @param array $permissions */ public function anyHave(...$permissions): bool { @@ -140,7 +140,7 @@ public function has(string $permission): bool /** * Check if none of the users have the specified permissions. * - * @param ...$permissions + * @param ...$permissions * @return bool */ public function noneHave(...$permissions): bool diff --git a/tests/Models/Role.php b/tests/Models/Role.php index 11ae940..8995c0a 100644 --- a/tests/Models/Role.php +++ b/tests/Models/Role.php @@ -5,7 +5,6 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; -use TPG\Deadbolt\Tests\Models\User; class Role extends Model { diff --git a/tests/Models/User.php b/tests/Models/User.php index b8898ce..d08e9a4 100644 --- a/tests/Models/User.php +++ b/tests/Models/User.php @@ -6,7 +6,6 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; -use TPG\Deadbolt\Tests\Models\Role; use TPG\Deadbolt\Traits\HasPermissions; class User extends Authenticatable diff --git a/tests/factories/UserFactory.php b/tests/factories/UserFactory.php index 0d65840..dac73f6 100644 --- a/tests/factories/UserFactory.php +++ b/tests/factories/UserFactory.php @@ -2,7 +2,6 @@ namespace TPG\Deadbolt\Tests\Factories; -use Faker\Generator as Faker; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Str; use TPG\Deadbolt\Tests\Models\User;