Skip to content

Commit

Permalink
Apply fixes from StyleCI (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
warrickbayman authored Jan 6, 2024
1 parent 57e0343 commit c038914
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 42 deletions.
6 changes: 3 additions & 3 deletions src/Contracts/DeadboltServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
interface DeadboltServiceInterface
{
/**
* @param array $config
* @param array $config
*/
public function __construct(array $config);

Expand All @@ -24,7 +24,7 @@ public function user(Model $model): User;
/**
* A collection of users to manipulate permissions for.
* *
* @param array<Model> $users
* @param array<Model> $users
*/
public function users(...$users): UserCollection;

Expand All @@ -41,7 +41,7 @@ public function all(): array;
/**
* Get the permission descriptions.
*
* @param array<string> $permissions
* @param array<string> $permissions
*/
public function describe(...$permissions): array;
}
12 changes: 6 additions & 6 deletions src/Contracts/UserCollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct(array $users, array $permissions, array $config);
/**
* Give the specified permissions to the user collection.
*
* @param array<string> $names
* @param array<string> $names
*/
public function give(...$names): UserCollectionInterface;

Expand All @@ -28,7 +28,7 @@ public function super(): UserCollectionInterface;
/**
* Revoke the specified permissions from the user collection.
*
* @param array<string> $names
* @param array<string> $names
*/
public function revoke(...$names): UserCollectionInterface;

Expand All @@ -40,7 +40,7 @@ public function revokeAll(): UserCollectionInterface;
/**
* Sync the specified permissions with the user collection.
*
* @param array<string> $names
* @param array<string> $names
*/
public function sync(...$names): UserCollectionInterface;

Expand All @@ -52,14 +52,14 @@ public function save(): UserCollectionInterface;
/**
* Check if all the users have all the specified permissions.
*
* @param array<string> $permissions
* @param array<string> $permissions
*/
public function allHave(...$permissions): bool;

/**
* Check if all the users have at least one of the specified permissions.
*
* @param array<string> $permissions
* @param array<string> $permissions
*/
public function anyHave(...$permissions): bool;

Expand All @@ -71,7 +71,7 @@ public function has(string $permission): bool;
/**
* Check if all the users have none of the specified permissions.
*
* @param array<string> $permissions
* @param array<string> $permissions
*/
public function noneHave(...$permissions): bool;
}
18 changes: 11 additions & 7 deletions src/Contracts/UserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct(Model $user, array $permissions, array $config);
/**
* Give the specified permissions.
*
* @param array<string>|string ...$names
* @param array<string>|string ...$names
* @return UserInterface
*
* @throws JsonException|NoSuchPermissionException
Expand All @@ -38,7 +38,7 @@ public function isSuper(): bool;
/**
* Revoke the specified permissions.
*
* @param array<string>|string $names
* @param array<string>|string $names
*
* @throws JsonException
*/
Expand All @@ -52,7 +52,7 @@ public function revokeAll(): UserInterface;
/**
* Sync permissions with the names provided.
*
* @param array<string>|string ...$names
* @param array<string>|string ...$names
*/
public function sync(...$names): UserInterface;

Expand All @@ -62,31 +62,35 @@ 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;

/**
* Check if all the specified permissions are assigned.
*
* @param array<string>|string $permissions
* @param array<string>|string $permissions
*
* @throws JsonException
*/
public function hasAll(...$permissions): bool;

/**
* Check if any of the specified permissions are assigned.
*
* @param array<string>|string $permissions
* @param array<string>|string $permissions
*
* @throws JsonException
*/
public function hasAny(...$permissions): bool;

/**
* Check if none of the specified permissions are assigned.
*
* @param array<string>|string ...$permissions
* @param array<string>|string ...$permissions
*
* @throws JsonException
*/
public function hasNone(...$permissions): bool;
Expand Down
4 changes: 2 additions & 2 deletions src/DeadboltService.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function user(Model $model): User
/**
* A collection of users to manipulate permissions for.
*
* @param array<Model> $users
* @param array<Model> $users
*/
public function users(...$users): UserCollection
{
Expand Down Expand Up @@ -67,7 +67,7 @@ public function all(): array
/**
* Get the permission descriptions.
*
* @param array<string> $permissions
* @param array<string> $permissions
*/
public function describe(...$permissions): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/DeadboltServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/NoSuchPermissionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
28 changes: 16 additions & 12 deletions src/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(protected Model $user, protected array $permissions,
/**
* Give the specified permissions.
*
* @param array<string>|string $names
* @param array<string>|string $names
* @return UserInterface
*
* @throws JsonException|NoSuchPermissionException
Expand All @@ -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
{
Expand Down Expand Up @@ -81,7 +81,7 @@ public function isSuper(): bool
/**
* Revoke the specified permissions.
*
* @param array<string>|string ...$names
* @param array<string>|string ...$names
* @return UserInterface
*
* @throws JsonException|NoSuchPermissionException
Expand All @@ -108,7 +108,8 @@ public function revokeAll(): UserInterface
/**
* Sync permissions with the names provided.
*
* @param array<string>|string $names
* @param array<string>|string $names
*
* @throws JsonException
* @throws NoSuchPermissionException
*/
Expand All @@ -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);
}

Expand All @@ -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
Expand All @@ -173,13 +174,14 @@ protected function userPermissions(): array
/**
* Check if all the specified permissions are assigned.
*
* @param array<string>|string $permissions
* @param array<string>|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;
}
}
Expand All @@ -190,7 +192,8 @@ public function hasAll(...$permissions): bool
/**
* Check if any of the specified permissions are assigned.
*
* @param array<string>|string ...$permissions
* @param array<string>|string ...$permissions
*
* @throws JsonException
*/
public function hasAny(...$permissions): bool
Expand All @@ -207,12 +210,13 @@ public function hasAny(...$permissions): bool
/**
* Check if none of the specified permissions are assigned.
*
* @param array<string>|string $permissions
* @param array<string>|string $permissions
*
* @throws JsonException
*/
public function hasNone(...$permissions): bool
{
return !$this->hasAny($permissions);
return ! $this->hasAny($permissions);
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/UserCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(array $users, array $permissions, array $config)
/**
* Give the specified permissions to the user collection.
*
* @param array<string> $names
* @param array<string> $names
*/
public function give(...$names): UserCollectionInterface
{
Expand All @@ -48,7 +48,7 @@ public function super(): UserCollectionInterface
/**
* Revoke the specified permissions from the user collection.
*
* @param array<string> $names
* @param array<string> $names
* @return UserCollectionInterface
*/
public function revoke(...$names): UserCollectionInterface
Expand All @@ -71,7 +71,7 @@ public function revokeAll(): UserCollectionInterface
/**
* Sync the specified permissions with the user collection.
*
* @param array<string> $names
* @param array<string> $names
* @return UserCollectionInterface
*/
public function sync(...$names): UserCollectionInterface
Expand Down Expand Up @@ -103,12 +103,12 @@ protected function callOnEachUser(string $name, mixed $arguments = null): UserCo
/**
* Check if all the users have the specified permissions.
*
* @param array<string> $permissions
* @param array<string> $permissions
*/
public function allHave(...$permissions): bool
{
foreach ($this->users as $user) {
if (!$user->hasAll($permissions)) {
if (! $user->hasAll($permissions)) {
return false;
}
}
Expand All @@ -119,7 +119,7 @@ public function allHave(...$permissions): bool
/**
* Check if any of the users have all the specified permissions.
*
* @param array<string> $permissions
* @param array<string> $permissions
*/
public function anyHave(...$permissions): bool
{
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
1 change: 0 additions & 1 deletion tests/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c038914

Please sign in to comment.