diff --git a/composer.json b/composer.json index 553b2c45..58eecec3 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,8 @@ "illuminate/events": "^11.0", "phpunit/phpunit": "^11.0", "orchestra/testbench": "^9.0", - "pestphp/pest": "3.x-dev" + "pestphp/pest": "3.x-dev", + "laravel/pint": "^1.14" }, "suggest": { "illuminate/console": "Allows running the bouncer:clean artisan command", diff --git a/middleware/ScopeBouncer.php b/middleware/ScopeBouncer.php index a9df6741..df17ee4a 100644 --- a/middleware/ScopeBouncer.php +++ b/middleware/ScopeBouncer.php @@ -2,9 +2,8 @@ namespace App\Http\Middleware; -use Silber\Bouncer\Bouncer; - use Closure; +use Silber\Bouncer\Bouncer; class ScopeBouncer { @@ -17,8 +16,6 @@ class ScopeBouncer /** * Constructor. - * - * @param \Silber\Bouncer\Bouncer $bouncer */ public function __construct(Bouncer $bouncer) { @@ -29,7 +26,6 @@ public function __construct(Bouncer $bouncer) * Set the proper Bouncer scope for the incoming request. * * @param \Illuminate\Http\Request $request - * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) diff --git a/migrations/create_bouncer_tables.php b/migrations/create_bouncer_tables.php index 3ae38dde..4e5dac92 100644 --- a/migrations/create_bouncer_tables.php +++ b/migrations/create_bouncer_tables.php @@ -1,10 +1,9 @@ foreign('role_id') - ->references('id')->on(Models::table('roles')) - ->onUpdate('cascade')->onDelete('cascade'); + ->references('id')->on(Models::table('roles')) + ->onUpdate('cascade')->onDelete('cascade'); }); Schema::create(Models::table('permissions'), function (Blueprint $table) { @@ -73,8 +72,8 @@ public function up() ); $table->foreign('ability_id') - ->references('id')->on(Models::table('abilities')) - ->onUpdate('cascade')->onDelete('cascade'); + ->references('id')->on(Models::table('abilities')) + ->onUpdate('cascade')->onDelete('cascade'); }); } diff --git a/src/BaseClipboard.php b/src/BaseClipboard.php index 02319002..e88feb0e 100644 --- a/src/BaseClipboard.php +++ b/src/BaseClipboard.php @@ -2,20 +2,16 @@ namespace Silber\Bouncer; +use Illuminate\Database\Eloquent\Model; +use InvalidArgumentException; use Silber\Bouncer\Database\Models; use Silber\Bouncer\Database\Queries\Abilities; -use InvalidArgumentException; -use Illuminate\Support\Collection; -use Illuminate\Database\Eloquent\Model; -use Illuminate\Contracts\Auth\Access\Gate; - abstract class BaseClipboard implements Contracts\Clipboard { /** * Determine if the given authority has the given ability. * - * @param \Illuminate\Database\Eloquent\Model $authority * @param string $ability * @param \Illuminate\Database\Eloquent\Model|string|null $model * @return bool @@ -28,7 +24,6 @@ public function check(Model $authority, $ability, $model = null) /** * Check if an authority has the given roles. * - * @param \Illuminate\Database\Eloquent\Model $authority * @param array|string $roles * @param string $boolean * @return bool @@ -74,13 +69,12 @@ protected function countMatchingRoles($authority, $roles) /** * Get the given authority's roles' IDs and names. * - * @param \Illuminate\Database\Eloquent\Model $authority * @return array */ public function getRolesLookup(Model $authority) { $roles = $authority->roles()->get([ - 'name', Models::role()->getQualifiedKeyName() + 'name', Models::role()->getQualifiedKeyName(), ])->pluck('name', Models::role()->getKeyName()); return ['ids' => $roles, 'names' => $roles->flip()]; @@ -89,7 +83,6 @@ public function getRolesLookup(Model $authority) /** * Get the given authority's roles' names. * - * @param \Illuminate\Database\Eloquent\Model $authority * @return \Illuminate\Support\Collection */ public function getRoles(Model $authority) @@ -100,7 +93,6 @@ public function getRoles(Model $authority) /** * Get a list of the authority's abilities. * - * @param \Illuminate\Database\Eloquent\Model $authority * @param bool $allowed * @return \Illuminate\Database\Eloquent\Collection */ @@ -112,7 +104,6 @@ public function getAbilities(Model $authority, $allowed = true) /** * Get a list of the authority's forbidden abilities. * - * @param \Illuminate\Database\Eloquent\Model $authority * @return \Illuminate\Database\Eloquent\Collection */ public function getForbiddenAbilities(Model $authority) diff --git a/src/Bouncer.php b/src/Bouncer.php index b3800bfd..6a911c37 100644 --- a/src/Bouncer.php +++ b/src/Bouncer.php @@ -2,14 +2,12 @@ namespace Silber\Bouncer; -use RuntimeException; -use Illuminate\Cache\NullStore; use Illuminate\Container\Container; -use Illuminate\Contracts\Cache\Store; -use Illuminate\Database\Eloquent\Model; use Illuminate\Contracts\Auth\Access\Gate; use Illuminate\Contracts\Cache\Repository as CacheRepository; - +use Illuminate\Contracts\Cache\Store; +use Illuminate\Database\Eloquent\Model; +use RuntimeException; use Silber\Bouncer\Contracts\Scope; use Silber\Bouncer\Database\Models; @@ -31,8 +29,6 @@ class Bouncer /** * Constructor. - * - * @param \Silber\Bouncer\Guard $guard */ public function __construct(Guard $guard) { @@ -181,7 +177,6 @@ public function sync($authority) /** * Start a chain, to check if the given authority has a certain role. * - * @param \Illuminate\Database\Eloquent\Model $authority * @return \Silber\Bouncer\Conductors\ChecksRoles */ public function is(Model $authority) @@ -231,10 +226,9 @@ public function registerClipboardAtContainer() /** * Use a cached clipboard with the given cache instance. * - * @param \Illuminate\Contracts\Cache\Store $cache * @return $this */ - public function cache(Store $cache = null) + public function cache(?Store $cache = null) { $cache = $cache ?: $this->resolve(CacheRepository::class)->getStore(); @@ -260,10 +254,9 @@ public function dontCache() /** * Clear the cache. * - * @param null|\Illuminate\Database\Eloquent\Model $authority * @return $this */ - public function refresh(Model $authority = null) + public function refresh(?Model $authority = null) { if ($this->usesCachedClipboard()) { $this->getClipboard()->refresh($authority); @@ -275,7 +268,6 @@ public function refresh(Model $authority = null) /** * Clear the cache for the given authority. * - * @param \Illuminate\Database\Eloquent\Model $authority * @return $this */ public function refreshFor(Model $authority) @@ -290,7 +282,6 @@ public function refreshFor(Model $authority) /** * Set the access gate instance. * - * @param \Illuminate\Contracts\Auth\Access\Gate $gate * @return $this */ public function setGate(Gate $gate) @@ -406,6 +397,7 @@ public function cannot($ability, $arguments = []) * Alias for the "can" method. * * @deprecated + * * @param string $ability * @param array|mixed $arguments * @return bool @@ -421,6 +413,7 @@ public function allows($ability, $arguments = []) * Alias for the "cannot" method. * * @deprecated + * * @param string $ability * @param array|mixed $arguments * @return bool @@ -433,7 +426,6 @@ public function denies($ability, $arguments = []) /** * Get an instance of the role model. * - * @param array $attributes * @return \Silber\Bouncer\Database\Role */ public function role(array $attributes = []) @@ -444,7 +436,6 @@ public function role(array $attributes = []) /** * Get an instance of the ability model. * - * @param array $attributes * @return \Silber\Bouncer\Database\Ability */ public function ability(array $attributes = []) @@ -521,7 +512,6 @@ public function useUserModel($model) /** * Set custom table names. * - * @param array $map * @return $this */ public function tables(array $map) @@ -534,10 +524,9 @@ public function tables(array $map) /** * Get the model scoping instance. * - * @param \Silber\Bouncer\Contracts\Scope|null $scope * @return mixed */ - public function scope(Scope $scope = null) + public function scope(?Scope $scope = null) { return Models::scope($scope); } @@ -546,7 +535,6 @@ public function scope(Scope $scope = null) * Resolve the given type from the container. * * @param string $abstract - * @param array $parameters * @return mixed */ protected function resolve($abstract, array $parameters = []) diff --git a/src/BouncerServiceProvider.php b/src/BouncerServiceProvider.php index 635e90a4..c6eee46e 100644 --- a/src/BouncerServiceProvider.php +++ b/src/BouncerServiceProvider.php @@ -2,15 +2,13 @@ namespace Silber\Bouncer; -use Illuminate\Support\Arr; -use Silber\Bouncer\Database\Models; -use Silber\Bouncer\Console\CleanCommand; - use Illuminate\Cache\ArrayStore; -use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Auth\Access\Gate; -use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Eloquent\Model as EloquentModel; +use Illuminate\Database\Eloquent\Relations\Relation; +use Illuminate\Support\ServiceProvider; +use Silber\Bouncer\Console\CleanCommand; +use Silber\Bouncer\Database\Models; class BouncerServiceProvider extends ServiceProvider { diff --git a/src/CachedClipboard.php b/src/CachedClipboard.php index 2940b030..d2aa2717 100644 --- a/src/CachedClipboard.php +++ b/src/CachedClipboard.php @@ -2,13 +2,12 @@ namespace Silber\Bouncer; -use Silber\Bouncer\Database\Models; - use Illuminate\Cache\TaggedCache; use Illuminate\Contracts\Cache\Store; -use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Collection; +use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Collection as BaseCollection; +use Silber\Bouncer\Database\Models; class CachedClipboard extends BaseClipboard implements Contracts\CachedClipboard { @@ -28,8 +27,6 @@ class CachedClipboard extends BaseClipboard implements Contracts\CachedClipboard /** * Constructor. - * - * @param \Illuminate\Contracts\Cache\Store $cache */ public function __construct(Store $cache) { @@ -39,7 +36,6 @@ public function __construct(Store $cache) /** * Set the cache instance. * - * @param \Illuminate\Contracts\Cache\Store $cache * @return $this */ public function setCache(Store $cache) @@ -66,7 +62,6 @@ public function getCache() /** * Determine if the given authority has the given ability, and return the ability ID. * - * @param \Illuminate\Database\Eloquent\Model $authority * @param string $ability * @param \Illuminate\Database\Eloquent\Model|string|null $model * @return int|bool|null @@ -164,7 +159,7 @@ protected function compileAbilityIdentifiers($ability, $model) protected function compileModelAbilityIdentifiers($ability, $model) { if ($model === '*') { - return ["{$ability}-*", "*-*"]; + return ["{$ability}-*", '*-*']; } $model = $model instanceof Model ? $model : new $model; @@ -175,7 +170,7 @@ protected function compileModelAbilityIdentifiers($ability, $model) "{$ability}-{$type}", "{$ability}-*", "*-{$type}", - "*-*", + '*-*', ]; if ($model->exists) { @@ -189,7 +184,6 @@ protected function compileModelAbilityIdentifiers($ability, $model) /** * Get the given authority's abilities. * - * @param \Illuminate\Database\Eloquent\Model $authority * @param bool $allowed * @return \Illuminate\Database\Eloquent\Collection */ @@ -211,7 +205,6 @@ public function getAbilities(Model $authority, $allowed = true) /** * Get a fresh copy of the given authority's abilities. * - * @param \Illuminate\Database\Eloquent\Model $authority * @param bool $allowed * @return \Illuminate\Database\Eloquent\Collection */ @@ -223,7 +216,6 @@ public function getFreshAbilities(Model $authority, $allowed) /** * Get the given authority's roles' IDs and names. * - * @param \Illuminate\Database\Eloquent\Model $authority * @return array */ public function getRolesLookup(Model $authority) @@ -239,7 +231,6 @@ public function getRolesLookup(Model $authority) * Get an item from the cache, or store the default value forever. * * @param string $key - * @param callable $callback * @return mixed */ protected function sear($key, callable $callback) @@ -259,7 +250,7 @@ protected function sear($key, callable $callback) */ public function refresh($authority = null) { - if ( ! is_null($authority)) { + if (! is_null($authority)) { return $this->refreshFor($authority); } @@ -275,7 +266,6 @@ public function refresh($authority = null) /** * Clear the cache for the given authority. * - * @param \Illuminate\Database\Eloquent\Model $authority * @return $this */ public function refreshFor(Model $authority) @@ -306,7 +296,6 @@ protected function refreshAllIteratively() /** * Get the cache key for the given model's cache type. * - * @param \Illuminate\Database\Eloquent\Model $model * @param string $type * @param bool $allowed * @return string @@ -335,7 +324,6 @@ protected function tag() /** * Deserialize an array of abilities into a collection of models. * - * @param array $abilities * @return \Illuminate\Database\Eloquent\Collection */ protected function deserializeAbilities(array $abilities) @@ -346,7 +334,6 @@ protected function deserializeAbilities(array $abilities) /** * Serialize a collection of ability models into a plain array. * - * @param \Illuminate\Database\Eloquent\Collection $abilities * @return array */ protected function serializeAbilities(Collection $abilities) diff --git a/src/Clipboard.php b/src/Clipboard.php index 506d40a2..e9feeeed 100644 --- a/src/Clipboard.php +++ b/src/Clipboard.php @@ -10,7 +10,6 @@ class Clipboard extends BaseClipboard /** * Determine if the given authority has the given ability, and return the ability ID. * - * @param \Illuminate\Database\Eloquent\Model $authority * @param string $ability * @param \Illuminate\Database\Eloquent\Model|string|null $model * @return int|bool|null @@ -29,7 +28,6 @@ public function checkGetId(Model $authority, $ability, $model = null) /** * Determine whether the given ability request is explicitely forbidden. * - * @param \Illuminate\Database\Eloquent\Model $authority * @param string $ability * @param \Illuminate\Database\Eloquent\Model|string|null $model * @return bool @@ -46,7 +44,6 @@ protected function isForbidden(Model $authority, $ability, $model = null) * * Returns null if the ability is not allowed. * - * @param \Illuminate\Database\Eloquent\Model $authority * @param string $ability * @param \Illuminate\Database\Eloquent\Model|string|null $model * @return \Illuminate\Database\Eloquent\Model|null @@ -62,7 +59,7 @@ protected function getAllowingAbility(Model $authority, $ability, $model = null) * Get the query for where the given authority has the given ability. * * @param \Illuminate\Database\Eloquent\Model $authority - * @param string $ability + * @param string $ability * @param \Illuminate\Database\Eloquent\Model|string|null $model * @param bool $allowed * @return \Illuminate\Database\Eloquent\Builder @@ -94,7 +91,7 @@ protected function constrainToSimpleAbility($query, $ability) return $query->where(function ($query) use ($ability) { $query->where('name', $ability)->whereNull('entity_type'); - $query->orWhere(function ($query) use ($ability) { + $query->orWhere(function ($query) { $query->where('name', '*')->where(function ($query) { $query->whereNull('entity_type')->orWhere('entity_type', '*'); }); diff --git a/src/Conductors/AssignsRoles.php b/src/Conductors/AssignsRoles.php index 2db197aa..1cb25bdc 100644 --- a/src/Conductors/AssignsRoles.php +++ b/src/Conductors/AssignsRoles.php @@ -2,10 +2,9 @@ namespace Silber\Bouncer\Conductors; -use Silber\Bouncer\Helpers; use Illuminate\Support\Collection; use Silber\Bouncer\Database\Models; -use Illuminate\Database\Eloquent\Model; +use Silber\Bouncer\Helpers; class AssignsRoles { @@ -19,7 +18,7 @@ class AssignsRoles /** * Constructor. * - * @param \Illuminate\Support\Collection|\Silber\Bouncer\Database\Role|string $roles + * @param \Illuminate\Support\Collection|\Silber\Bouncer\Database\Role|string $roles */ public function __construct($roles) { @@ -48,9 +47,7 @@ public function to($authority) /** * Assign the given roles to the given authorities. * - * @param \Illuminate\Support\Collection $roles - * @param string $authorityClass - * @param \Illuminate\Support\Collection $authorityIds + * @param string $authorityClass * @return void */ protected function assignRoles(Collection $roles, $authorityClass, Collection $authorityIds) @@ -72,7 +69,7 @@ protected function assignRoles(Collection $roles, $authorityClass, Collection $a * Get the pivot table records for the roles already assigned. * * @param \Illuminate\Support\Collection $roleIds - * @param string $morphType + * @param string $morphType * @param \Illuminate\Support\Collection $authorityIds * @return \Illuminate\Support\Collection */ @@ -92,7 +89,7 @@ protected function getExistingAttachRecords($roleIds, $morphType, $authorityIds) * Build the raw attach records for the assigned roles pivot table. * * @param \Illuminate\Support\Collection $roleIds - * @param string $morphType + * @param string $morphType * @param \Illuminate\Support\Collection $authorityIds * @return \Illuminate\Support\Collection */ @@ -112,8 +109,6 @@ protected function buildAttachRecords($roleIds, $morphType, $authorityIds) /** * Save the non-existing attach records in the DB. * - * @param \Illuminate\Support\Collection $records - * @param \Illuminate\Support\Collection $existing * @return void */ protected function createMissingAssignRecords(Collection $records, Collection $existing) @@ -132,7 +127,6 @@ protected function createMissingAssignRecords(Collection $records, Collection $e /** * Get a string identifying the given attach record. * - * @param array $record * @return string */ protected function getAttachRecordHash(array $record) diff --git a/src/Conductors/ChecksRoles.php b/src/Conductors/ChecksRoles.php index df8f9b15..bd59e4b2 100644 --- a/src/Conductors/ChecksRoles.php +++ b/src/Conductors/ChecksRoles.php @@ -23,9 +23,6 @@ class ChecksRoles /** * Constructor. - * - * @param \Illuminate\Database\Eloquent\Model $authority - * @param \Silber\Bouncer\Contracts\Clipboard $clipboard */ public function __construct(Model $authority, Clipboard $clipboard) { diff --git a/src/Conductors/Concerns/AssociatesAbilities.php b/src/Conductors/Concerns/AssociatesAbilities.php index 559923ec..de221ca0 100644 --- a/src/Conductors/Concerns/AssociatesAbilities.php +++ b/src/Conductors/Concerns/AssociatesAbilities.php @@ -2,9 +2,9 @@ namespace Silber\Bouncer\Conductors\Concerns; +use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Arr; use Silber\Bouncer\Database\Models; -use Illuminate\Database\Eloquent\Model; trait AssociatesAbilities { @@ -15,7 +15,6 @@ trait AssociatesAbilities * * @param \Illuminate\Database\Eloquent\model|array|int|string $abilities * @param \Illuminate\Database\Eloquent\Model|string|null $model - * @param array $attributes * @return \Silber\Bouncer\Conductors\Lazy\ConductsAbilities|null */ public function to($abilities, $model = null, array $attributes = []) @@ -51,7 +50,6 @@ protected function getAuthority() * Get the IDs of the associated abilities. * * @param \Illuminate\Database\Eloquent\Model|null $authority - * @param array $abilityIds * @return array */ protected function getAssociatedAbilityIds($authority, array $abilityIds) @@ -65,7 +63,7 @@ protected function getAssociatedAbilityIds($authority, array $abilityIds) $table = Models::table('abilities'); $relation->whereIn("{$table}.id", $abilityIds) - ->wherePivot('forbidden', '=', $this->forbidding); + ->wherePivot('forbidden', '=', $this->forbidding); Models::scope()->applyToRelation($relation); @@ -75,7 +73,6 @@ protected function getAssociatedAbilityIds($authority, array $abilityIds) /** * Get the IDs of the abilities associated with everyone. * - * @param array $abilityIds * @return array */ protected function getAbilityIdsAssociatedWithEveryone(array $abilityIds) @@ -93,11 +90,9 @@ protected function getAbilityIdsAssociatedWithEveryone(array $abilityIds) /** * Associate the given ability IDs on the permissions table. * - * @param array $ids - * @param \Illuminate\Database\Eloquent\Model|null $authority * @return void */ - protected function associateAbilities(array $ids, Model $authority = null) + protected function associateAbilities(array $ids, ?Model $authority = null) { $ids = array_diff($ids, $this->getAssociatedAbilityIds($authority, $ids, false)); @@ -111,8 +106,6 @@ protected function associateAbilities(array $ids, Model $authority = null) /** * Associate these abilities with the given authority. * - * @param array $ids - * @param \Illuminate\Database\Eloquent\Model $authority * @return void */ protected function associateAbilitiesToAuthority(array $ids, Model $authority) @@ -127,7 +120,6 @@ protected function associateAbilitiesToAuthority(array $ids, Model $authority) /** * Associate these abilities with everyone. * - * @param array $ids * @return void */ protected function associateAbilitiesToEveryone(array $ids) diff --git a/src/Conductors/Concerns/ConductsAbilities.php b/src/Conductors/Concerns/ConductsAbilities.php index 9be9eff0..c1a2de48 100644 --- a/src/Conductors/Concerns/ConductsAbilities.php +++ b/src/Conductors/Concerns/ConductsAbilities.php @@ -2,16 +2,15 @@ namespace Silber\Bouncer\Conductors\Concerns; -use Silber\Bouncer\Helpers; use Illuminate\Support\Collection; use Silber\Bouncer\Conductors\Lazy; +use Silber\Bouncer\Helpers; trait ConductsAbilities { /** * Allow/disallow all abilities on everything. * - * @param array $attributes * @return mixed */ public function everything(array $attributes = []) @@ -23,7 +22,6 @@ public function everything(array $attributes = []) * Allow/disallow all abilities on the given model. * * @param string|array|\Illuminate\Database\Eloquent\Model $models - * @param array $attributes * @return void */ public function toManage($models, array $attributes = []) @@ -41,7 +39,6 @@ public function toManage($models, array $attributes = []) * Allow/disallow owning the given model. * * @param string|object $model - * @param array $attributes * @return \Silber\Bouncer\Conductors\Lazy\HandlesOwnership */ public function toOwn($model, array $attributes = []) @@ -52,7 +49,6 @@ public function toOwn($model, array $attributes = []) /** * Allow/disallow owning all models. * - * @param array $attributes * @return \Silber\Bouncer\Conductors\Lazy\HandlesOwnership */ public function toOwnEverything(array $attributes = []) diff --git a/src/Conductors/Concerns/DisassociatesAbilities.php b/src/Conductors/Concerns/DisassociatesAbilities.php index bd4e6598..fbdb26fb 100644 --- a/src/Conductors/Concerns/DisassociatesAbilities.php +++ b/src/Conductors/Concerns/DisassociatesAbilities.php @@ -2,13 +2,9 @@ namespace Silber\Bouncer\Conductors\Concerns; -use Silber\Bouncer\Database\Models; -use Silber\Bouncer\Database\Ability; - -use InvalidArgumentException; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Collection; -use Illuminate\Database\Eloquent\Relations\MorphToMany; +use Silber\Bouncer\Database\Ability; +use Silber\Bouncer\Database\Models; trait DisassociatesAbilities { @@ -19,7 +15,6 @@ trait DisassociatesAbilities * * @param mixed $abilities * @param \Illuminate\Database\Eloquent\Model|string|null $entity - * @param array $attributes * @return bool|\Silber\Bouncer\Conductors\Lazy\ConductsAbilities */ public function to($abilities, $entity = null, array $attributes = []) @@ -39,7 +34,6 @@ public function to($abilities, $entity = null, array $attributes = []) * Detach the given IDs from the authority. * * @param \Illuminate\Database\Eloquent\Model|null $authority - * @param array $ids * @return void */ protected function disassociateAbilities($authority, array $ids) @@ -54,21 +48,18 @@ protected function disassociateAbilities($authority, array $ids) /** * Disassociate the authority from the abilities with the given IDs. * - * @param \Illuminate\Database\Eloquent\Model $authority - * @param array $ids * @return void */ protected function disassociateAuthority(Model $authority, array $ids) { $this->getAbilitiesPivotQuery($authority, $ids) - ->where($this->constraints()) - ->delete(); + ->where($this->constraints()) + ->delete(); } /** * Get the base abilities pivot query. * - * @param \Illuminate\Database\Eloquent\Model $model * @param array $ids * @return \Illuminate\Database\Query\Builder */ @@ -90,7 +81,6 @@ protected function getAbilitiesPivotQuery(Model $model, $ids) /** * Disassociate everyone from the abilities with the given IDs. * - * @param array $ids * @return void */ protected function disassociateEveryone(array $ids) diff --git a/src/Conductors/Concerns/FindsAndCreatesAbilities.php b/src/Conductors/Concerns/FindsAndCreatesAbilities.php index 64e6bbb6..ca5f2e9e 100644 --- a/src/Conductors/Concerns/FindsAndCreatesAbilities.php +++ b/src/Conductors/Concerns/FindsAndCreatesAbilities.php @@ -2,13 +2,12 @@ namespace Silber\Bouncer\Conductors\Concerns; -use Silber\Bouncer\Helpers; -use Silber\Bouncer\Database\Models; - +use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Arr; -use InvalidArgumentException; use Illuminate\Support\Collection; -use Illuminate\Database\Eloquent\Model; +use InvalidArgumentException; +use Silber\Bouncer\Database\Models; +use Silber\Bouncer\Helpers; trait FindsAndCreatesAbilities { @@ -17,7 +16,6 @@ trait FindsAndCreatesAbilities * * @param \Illuminate\Database\Eloquent\model|array|int $abilities * @param \Illuminate\Database\Eloquent\Model|string|array|null $model - * @param array $attributes * @return array */ protected function getAbilityIds($abilities, $model = null, array $attributes = []) @@ -26,7 +24,7 @@ protected function getAbilityIds($abilities, $model = null, array $attributes = return [$abilities->getKey()]; } - if ( ! is_null($model)) { + if (! is_null($model)) { return $this->getModelAbilityKeys($abilities, $model, $attributes); } @@ -46,13 +44,11 @@ protected function getAbilityIds($abilities, $model = null, array $attributes = * * The map should use the ['ability-name' => Entity::class] format. * - * @param array $map - * @param array $attributes * @return array */ protected function getAbilityIdsFromMap(array $map, array $attributes) { - list($map, $list) = Helpers::partition($map, function ($value, $key) { + [$map, $list] = Helpers::partition($map, function ($value, $key) { return ! is_int($key); }); @@ -65,7 +61,6 @@ protected function getAbilityIdsFromMap(array $map, array $attributes) * Get the ability IDs from the provided array, creating the ones that don't exist. * * @param iterable $abilities - * @param array $attributes * @return array */ protected function getAbilityIdsFromArray($abilities, array $attributes) @@ -75,7 +70,7 @@ protected function getAbilityIdsFromArray($abilities, array $attributes) $keyName = Models::ability()->getKeyName(); $groups['strings'] = $this->abilitiesByName($groups['strings'], $attributes) - ->pluck($keyName)->all(); + ->pluck($keyName)->all(); $groups['models'] = Arr::pluck($groups['models'], $keyName); @@ -87,7 +82,6 @@ protected function getAbilityIdsFromArray($abilities, array $attributes) * * @param array|string $abilities * @param \Illuminate\Database\Eloquent\Model|string|array $model - * @param array $attributes * @return array */ protected function getModelAbilityKeys($abilities, $model, array $attributes) @@ -108,7 +102,6 @@ protected function getModelAbilityKeys($abilities, $model, array $attributes) * * @param string $ability * @param \Illuminate\Database\Eloquent\Model|string $entity - * @param array $attributes * @return \Silber\Bouncer\Database\Ability */ protected function getModelAbility($ability, $entity, array $attributes) @@ -133,9 +126,9 @@ protected function findAbility($ability, $entity, $attributes) $onlyOwned = isset($attributes['only_owned']) ? $attributes['only_owned'] : false; $query = Models::ability() - ->where('name', $ability) - ->forModel($entity, true) - ->where('only_owned', $onlyOwned); + ->where('name', $ability) + ->forModel($entity, true) + ->where('only_owned', $onlyOwned); return Models::scope()->applyToModelQuery($query)->first(); } @@ -167,14 +160,14 @@ protected function getEntityInstance($model) return '*'; } - if ( ! $model instanceof Model) { + if (! $model instanceof Model) { return new $model; } // Creating an ability for a non-existent model gives the authority that // ability on all instances of that model. If the developer passed in // a model instance that does not exist, it is probably a mistake. - if ( ! $model->exists) { + if (! $model->exists) { throw new InvalidArgumentException( 'The model does not exist. To edit access to all models, use the class name instead' ); diff --git a/src/Conductors/ForbidsAbilities.php b/src/Conductors/ForbidsAbilities.php index 8808f27d..f4874249 100644 --- a/src/Conductors/ForbidsAbilities.php +++ b/src/Conductors/ForbidsAbilities.php @@ -2,9 +2,6 @@ namespace Silber\Bouncer\Conductors; -use Silber\Bouncer\Database\Models; -use Illuminate\Database\Eloquent\Model; - class ForbidsAbilities { use Concerns\AssociatesAbilities; @@ -26,7 +23,7 @@ class ForbidsAbilities /** * Constructor. * - * @param \Illuminate\Database\Eloquent\Model|string|null $authority + * @param \Illuminate\Database\Eloquent\Model|string|null $authority */ public function __construct($authority = null) { diff --git a/src/Conductors/GivesAbilities.php b/src/Conductors/GivesAbilities.php index 99979493..f28f0ffb 100644 --- a/src/Conductors/GivesAbilities.php +++ b/src/Conductors/GivesAbilities.php @@ -2,9 +2,6 @@ namespace Silber\Bouncer\Conductors; -use Silber\Bouncer\Database\Models; -use Illuminate\Database\Eloquent\Model; - class GivesAbilities { use Concerns\AssociatesAbilities; @@ -26,7 +23,7 @@ class GivesAbilities /** * Constructor. * - * @param \Illuminate\Database\Eloquent\Model|string|null $authority + * @param \Illuminate\Database\Eloquent\Model|string|null $authority */ public function __construct($authority = null) { diff --git a/src/Conductors/Lazy/ConductsAbilities.php b/src/Conductors/Lazy/ConductsAbilities.php index 5b038cc5..aca83d85 100644 --- a/src/Conductors/Lazy/ConductsAbilities.php +++ b/src/Conductors/Lazy/ConductsAbilities.php @@ -35,9 +35,9 @@ class ConductsAbilities /** * Constructor. * - * @param \Silber\Bouncer\Conductors\Concerns\ConductsAbilities $conductor - * @param mixed $model - * @param array $attributes + * @param \Silber\Bouncer\Conductors\Concerns\ConductsAbilities $conductor + * @param mixed $model + * @param array $attributes */ public function __construct($conductor, $abilities) { @@ -48,7 +48,6 @@ public function __construct($conductor, $abilities) /** * Sets that the abilities should be applied towards everything. * - * @param array $attributes * @return void */ public function everything(array $attributes = []) @@ -60,7 +59,6 @@ public function everything(array $attributes = []) /** * Destructor. - * */ public function __destruct() { diff --git a/src/Conductors/Lazy/HandlesOwnership.php b/src/Conductors/Lazy/HandlesOwnership.php index 00cc31db..780bd3d9 100644 --- a/src/Conductors/Lazy/HandlesOwnership.php +++ b/src/Conductors/Lazy/HandlesOwnership.php @@ -35,9 +35,8 @@ class HandlesOwnership /** * Constructor. * - * @param \Silber\Bouncer\Conductors\Concerns\ConductsAbilities $conductor - * @param string|object $model - * @param array $attributes + * @param \Silber\Bouncer\Conductors\Concerns\ConductsAbilities $conductor + * @param string|object $model */ public function __construct($conductor, $model, array $attributes = []) { @@ -50,7 +49,6 @@ public function __construct($conductor, $model, array $attributes = []) * Limit ownership to the given ability. * * @param string|string[] $ability - * @param array $attributes * @return void */ public function to($ability, array $attributes = []) @@ -62,7 +60,6 @@ public function to($ability, array $attributes = []) /** * Destructor. - * */ public function __destruct() { diff --git a/src/Conductors/RemovesAbilities.php b/src/Conductors/RemovesAbilities.php index c460d512..9219e089 100644 --- a/src/Conductors/RemovesAbilities.php +++ b/src/Conductors/RemovesAbilities.php @@ -23,7 +23,7 @@ class RemovesAbilities /** * Constructor. * - * @param \Illuminate\Database\Eloquent\Model|string|null $authority + * @param \Illuminate\Database\Eloquent\Model|string|null $authority */ public function __construct($authority = null) { diff --git a/src/Conductors/RemovesRoles.php b/src/Conductors/RemovesRoles.php index 6dc09bd8..bf4205e0 100644 --- a/src/Conductors/RemovesRoles.php +++ b/src/Conductors/RemovesRoles.php @@ -2,10 +2,10 @@ namespace Silber\Bouncer\Conductors; -use Silber\Bouncer\Helpers; -use Silber\Bouncer\Database\Role; -use Silber\Bouncer\Database\Models; use Illuminate\Database\Eloquent\Model; +use Silber\Bouncer\Database\Models; +use Silber\Bouncer\Database\Role; +use Silber\Bouncer\Helpers; class RemovesRoles { @@ -19,7 +19,7 @@ class RemovesRoles /** * Constructor. * - * @param \Illuminate\Support\Collection|\Silber\Bouncer\Database\Role|string $roles + * @param \Illuminate\Support\Collection|\Silber\Bouncer\Database\Role|string $roles */ public function __construct($roles) { @@ -52,7 +52,7 @@ public function from($authority) */ protected function getRoleIds() { - list($models, $names) = Helpers::partition($this->roles, function ($role) { + [$models, $names] = Helpers::partition($this->roles, function ($role) { return $role instanceof Model; }); @@ -78,17 +78,17 @@ protected function getRoleIdsFromNames(array $names) $key = Models::role()->getKeyName(); return Models::role() - ->whereIn('name', $names) - ->get([$key]) - ->pluck($key); + ->whereIn('name', $names) + ->get([$key]) + ->pluck($key); } /** * Retract the given roles from the given authorities. * * @param array $roleIds - * @param string $authorityClass - * @param array $authorityIds + * @param string $authorityClass + * @param array $authorityIds * @return void */ protected function retractRoles($roleIds, $authorityClass, $authorityIds) diff --git a/src/Conductors/SyncsRolesAndAbilities.php b/src/Conductors/SyncsRolesAndAbilities.php index 40ce7b57..e2f77989 100644 --- a/src/Conductors/SyncsRolesAndAbilities.php +++ b/src/Conductors/SyncsRolesAndAbilities.php @@ -2,13 +2,9 @@ namespace Silber\Bouncer\Conductors; -use Silber\Bouncer\Helpers; -use Silber\Bouncer\Database\Models; - -use Illuminate\Support\Arr; -use Illuminate\Support\Collection; -use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Support\Arr; +use Silber\Bouncer\Database\Models; class SyncsRolesAndAbilities { @@ -24,7 +20,7 @@ class SyncsRolesAndAbilities /** * Constructor. * - * @param \Illuminate\Database\Eloquent\Model|string $authority + * @param \Illuminate\Database\Eloquent\Model|string $authority */ public function __construct($authority) { @@ -81,10 +77,10 @@ protected function syncAbilities($abilities, $options = ['forbidden' => false]) $relation = $authority->abilities(); $this->newPivotQuery($relation) - ->where('entity_type', $authority->getMorphClass()) - ->whereNotIn($relation->getRelatedPivotKeyName(), $abilityKeys) - ->where('forbidden', $options['forbidden']) - ->delete(); + ->where('entity_type', $authority->getMorphClass()) + ->whereNotIn($relation->getRelatedPivotKeyName(), $abilityKeys) + ->where('forbidden', $options['forbidden']) + ->delete(); if ($options['forbidden']) { (new ForbidsAbilities($this->authority))->to($abilityKeys); @@ -102,7 +98,7 @@ protected function getAuthority() { if (is_string($this->authority)) { $this->authority = Models::role()->firstOrCreate([ - 'name' => $this->authority + 'name' => $this->authority, ]); } @@ -128,8 +124,6 @@ protected function getAbilitiesQualifiedKeyName() * BelongsToMany@sync - which we sadly cannot use because * our scope sets a "closure where" on the pivot table. * - * @param array $ids - * @param \Illuminate\Database\Eloquent\Relations\BelongsToMany $relation * @return void */ protected function sync(array $ids, BelongsToMany $relation) @@ -150,8 +144,6 @@ protected function sync(array $ids, BelongsToMany $relation) /** * Detach the records with the given IDs from the relationship. * - * @param array $ids - * @param \Illuminate\Database\Eloquent\Relations\BelongsToMany $relation * @return void */ public function detach(array $ids, BelongsToMany $relation) @@ -161,14 +153,13 @@ public function detach(array $ids, BelongsToMany $relation) } $this->newPivotQuery($relation) - ->whereIn($relation->getRelatedPivotKeyName(), $ids) - ->delete(); + ->whereIn($relation->getRelatedPivotKeyName(), $ids) + ->delete(); } /** * Get a scoped query for the pivot table. * - * @param \Illuminate\Database\Eloquent\Relations\BelongsToMany $relation * @return \Illuminate\Database\Query\Builder */ protected function newPivotQuery(BelongsToMany $relation) @@ -190,7 +181,7 @@ protected function newPivotQuery(BelongsToMany $relation) * Pluck the values of the given column using the provided query. * * @param mixed $query - * @param string $column + * @param string $column * @return string[] */ protected function pluck($query, $column) diff --git a/src/Conductors/UnforbidsAbilities.php b/src/Conductors/UnforbidsAbilities.php index 34f0b7a8..8dfa2890 100644 --- a/src/Conductors/UnforbidsAbilities.php +++ b/src/Conductors/UnforbidsAbilities.php @@ -23,7 +23,7 @@ class UnforbidsAbilities /** * Constructor. * - * @param \Illuminate\Database\Eloquent\Model|string|null $authority + * @param \Illuminate\Database\Eloquent\Model|string|null $authority */ public function __construct($authority = null) { diff --git a/src/Console/CleanCommand.php b/src/Console/CleanCommand.php index cd886711..1bc0183f 100644 --- a/src/Console/CleanCommand.php +++ b/src/Console/CleanCommand.php @@ -2,11 +2,10 @@ namespace Silber\Bouncer\Console; -use Illuminate\Support\Str; use Illuminate\Console\Command; -use Illuminate\Support\Collection; -use Silber\Bouncer\Database\Models; use Illuminate\Database\Eloquent\Relations\Relation; +use Illuminate\Support\Str; +use Silber\Bouncer\Database\Models; class CleanCommand extends Command { @@ -161,8 +160,8 @@ protected function getBaseOrphanedQuery() $table = $this->abilitiesTable(); return Models::ability() - ->whereNotNull("{$table}.entity_id") - ->where("{$table}.entity_type", '!=', '*'); + ->whereNotNull("{$table}.entity_id") + ->where("{$table}.entity_type", '!=', '*'); } /** diff --git a/src/Constraints/Builder.php b/src/Constraints/Builder.php index 3fff953d..f8c91a5b 100644 --- a/src/Constraints/Builder.php +++ b/src/Constraints/Builder.php @@ -16,7 +16,6 @@ class Builder /** * Constructor. - * */ public function __construct() { @@ -111,7 +110,6 @@ public function build() * Add a nested "where" clause. * * @param string $logicalOperator 'and'|'or' - * @param \Closure $callback * @return $this */ protected function whereNested($logicalOperator, Closure $callback) diff --git a/src/Constraints/ColumnConstraint.php b/src/Constraints/ColumnConstraint.php index ffc098fa..bd75876e 100644 --- a/src/Constraints/ColumnConstraint.php +++ b/src/Constraints/ColumnConstraint.php @@ -6,7 +6,6 @@ class ColumnConstraint extends Constraint { - /** * The column on the entity against which to compare. * @@ -24,9 +23,9 @@ class ColumnConstraint extends Constraint /** * Constructor. * - * @param string $a - * @param string $operator - * @param mixed $b + * @param string $a + * @param string $operator + * @param mixed $b */ public function __construct($a, $operator, $b) { @@ -38,11 +37,9 @@ public function __construct($a, $operator, $b) /** * Determine whether the given entity/authority passes the constraint. * - * @param \Illuminate\Database\Eloquent\Model $entity - * @param \Illuminate\Database\Eloquent\Model|null $authority * @return bool */ - public function check(Model $entity, Model $authority = null) + public function check(Model $entity, ?Model $authority = null) { if (is_null($authority)) { return false; @@ -54,7 +51,6 @@ public function check(Model $entity, Model $authority = null) /** * Create a new instance from the raw data. * - * @param array $data * @return static */ public static function fromData(array $data) diff --git a/src/Constraints/Constrainer.php b/src/Constraints/Constrainer.php index 7f839d42..b9fb9054 100644 --- a/src/Constraints/Constrainer.php +++ b/src/Constraints/Constrainer.php @@ -9,7 +9,6 @@ interface Constrainer /** * Create a new instance from the raw data. * - * @param array $data * @return static */ public static function fromData(array $data); @@ -24,11 +23,9 @@ public function data(); /** * Determine whether the given entity/authority passes this constraint. * - * @param \Illuminate\Database\Eloquent\Model $entity - * @param \Illuminate\Database\Eloquent\Model|null $authority * @return bool */ - public function check(Model $entity, Model $authority = null); + public function check(Model $entity, ?Model $authority = null); /** * Set the logical operator to use when checked after a previous constrainer. @@ -41,21 +38,20 @@ public function logicalOperator($operator = null); /** * Checks whether the logical operator is an "and" operator. * - * @param string $operator + * @param string $operator */ public function isAnd(); /** * Checks whether the logical operator is an "and" operator. * - * @param string $operator + * @param string $operator */ public function isOr(); /** * Determine whether the given constrainer is equal to this object. * - * @param \Silber\Bouncer\Constraints\Constrainer $constrainer * @return bool */ public function equals(Constrainer $constrainer); diff --git a/src/Constraints/Constraint.php b/src/Constraints/Constraint.php index 2bd2321e..1c25bdac 100644 --- a/src/Constraints/Constraint.php +++ b/src/Constraints/Constraint.php @@ -2,9 +2,9 @@ namespace Silber\Bouncer\Constraints; -use Silber\Bouncer\Helpers; -use InvalidArgumentException; use Illuminate\Database\Eloquent\Model; +use InvalidArgumentException; +use Silber\Bouncer\Helpers; abstract class Constraint implements Constrainer { @@ -25,11 +25,9 @@ abstract class Constraint implements Constrainer /** * Determine whether the given entity/authority passes this constraint. * - * @param \Illuminate\Database\Eloquent\Model $entity - * @param \Illuminate\Database\Eloquent\Model|null $authority * @return bool */ - abstract public function check(Model $entity, Model $authority = null); + abstract public function check(Model $entity, ?Model $authority = null); /** * Create a new constraint for where a column matches the given value. @@ -41,14 +39,13 @@ abstract public function check(Model $entity, Model $authority = null); */ public static function where($column, $operator, $value = null) { - list($operator, $value) = static::prepareOperatorAndValue( + [$operator, $value] = static::prepareOperatorAndValue( $operator, $value, func_num_args() === 2 ); return new ValueConstraint($column, $operator, $value); } - /** * Create a new constraint for where a column matches the given value, * with the logical operator set to "or". @@ -73,7 +70,7 @@ public static function orWhere($column, $operator, $value = null) */ public static function whereColumn($a, $operator, $b = null) { - list($operator, $b) = static::prepareOperatorAndValue( + [$operator, $b] = static::prepareOperatorAndValue( $operator, $b, func_num_args() === 2 ); @@ -116,7 +113,7 @@ public function logicalOperator($operator = null) /** * Checks whether the logical operator is an "and" operator. * - * @param string $operator + * @param string $operator */ public function isAnd() { @@ -126,7 +123,7 @@ public function isAnd() /** * Checks whether the logical operator is an "and" operator. * - * @param string $operator + * @param string $operator */ public function isOr() { @@ -136,7 +133,6 @@ public function isOr() /** * Determine whether the given constrainer is equal to this object. * - * @param \Silber\Bouncer\Constraints\Constrainer $constrainer * @return bool */ public function equals(Constrainer $constrainer) diff --git a/src/Constraints/Group.php b/src/Constraints/Group.php index 49df15f7..aa9e9cbc 100644 --- a/src/Constraints/Group.php +++ b/src/Constraints/Group.php @@ -2,9 +2,9 @@ namespace Silber\Bouncer\Constraints; -use Silber\Bouncer\Helpers; -use Illuminate\Support\Collection; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Collection; +use Silber\Bouncer\Helpers; class Group implements Constrainer { @@ -25,7 +25,7 @@ class Group implements Constrainer /** * Constructor. * - * @param iterable<\Silber\Bouncer\Constraints\Constrainer> $constraints + * @param iterable<\Silber\Bouncer\Constraints\Constrainer> $constraints */ public function __construct($constraints = []) { @@ -55,7 +55,6 @@ public static function withOr() /** * Create a new instance from the raw data. * - * @param array $data * @return static */ public static function fromData(array $data) @@ -69,8 +68,6 @@ public static function fromData(array $data) /** * Add the given constraint to the list of constraints. - * - * @param \Silber\Bouncer\Constraints\Constrainer $constraint */ public function add(Constrainer $constraint) { @@ -82,11 +79,9 @@ public function add(Constrainer $constraint) /** * Determine whether the given entity/authority passes this constraint. * - * @param \Illuminate\Database\Eloquent\Model $entity - * @param \Illuminate\Database\Eloquent\Model|null $authority * @return bool */ - public function check(Model $entity, Model $authority = null) + public function check(Model $entity, ?Model $authority = null) { if ($this->constraints->isEmpty()) { return true; @@ -125,7 +120,7 @@ public function logicalOperator($operator = null) /** * Checks whether the logical operator is an "and" operator. * - * @param string $operator + * @param string $operator */ public function isAnd() { @@ -135,7 +130,7 @@ public function isAnd() /** * Checks whether the logical operator is an "and" operator. * - * @param string $operator + * @param string $operator */ public function isOr() { @@ -145,7 +140,6 @@ public function isOr() /** * Determine whether the given constrainer is equal to this object. * - * @param \Silber\Bouncer\Constraints\Constrainer $constrainer * @return bool */ public function equals(Constrainer $constrainer) diff --git a/src/Constraints/ValueConstraint.php b/src/Constraints/ValueConstraint.php index 72485486..e575311b 100644 --- a/src/Constraints/ValueConstraint.php +++ b/src/Constraints/ValueConstraint.php @@ -23,9 +23,9 @@ class ValueConstraint extends Constraint /** * Constructor. * - * @param string $column - * @param string $operator - * @param mixed $value + * @param string $column + * @param string $operator + * @param mixed $value */ public function __construct($column, $operator, $value) { @@ -37,11 +37,9 @@ public function __construct($column, $operator, $value) /** * Determine whether the given entity/authority passed this constraint. * - * @param \Illuminate\Database\Eloquent\Model $entity - * @param \Illuminate\Database\Eloquent\Model|null $authority * @return bool */ - public function check(Model $entity, Model $authority = null) + public function check(Model $entity, ?Model $authority = null) { return $this->compare($entity->{$this->column}, $this->value); } @@ -49,7 +47,6 @@ public function check(Model $entity, Model $authority = null) /** * Create a new instance from the raw data. * - * @param array $data * @return static */ public static function fromData(array $data) diff --git a/src/Contracts/CachedClipboard.php b/src/Contracts/CachedClipboard.php index 10f0486b..c87e39b2 100644 --- a/src/Contracts/CachedClipboard.php +++ b/src/Contracts/CachedClipboard.php @@ -10,7 +10,6 @@ interface CachedClipboard extends Clipboard /** * Set the cache instance. * - * @param \Illuminate\Contracts\Cache\Store $cache * @return $this */ public function setCache(Store $cache); @@ -25,7 +24,6 @@ public function getCache(); /** * Get a fresh copy of the given authority's abilities. * - * @param \Illuminate\Database\Eloquent\Model $authority * @param bool $allowed * @return \Illuminate\Database\Eloquent\Collection */ @@ -42,7 +40,6 @@ public function refresh($authority = null); /** * Clear the cache for the given authority. * - * @param \Illuminate\Database\Eloquent\Model $authority * @return $this */ public function refreshFor(Model $authority); diff --git a/src/Contracts/Clipboard.php b/src/Contracts/Clipboard.php index 0de07760..0a6a0cd2 100644 --- a/src/Contracts/Clipboard.php +++ b/src/Contracts/Clipboard.php @@ -3,14 +3,12 @@ namespace Silber\Bouncer\Contracts; use Illuminate\Database\Eloquent\Model; -use Illuminate\Contracts\Auth\Access\Gate; interface Clipboard { /** * Determine if the given authority has the given ability. * - * @param \Illuminate\Database\Eloquent\Model $authority * @param string $ability * @param \Illuminate\Database\Eloquent\Model|string|null $model * @return bool @@ -20,7 +18,6 @@ public function check(Model $authority, $ability, $model = null); /** * Determine if the given authority has the given ability, and return the ability ID. * - * @param \Illuminate\Database\Eloquent\Model $authority * @param string $ability * @param \Illuminate\Database\Eloquent\Model|string|null $model * @return int|bool|null @@ -30,7 +27,6 @@ public function checkGetId(Model $authority, $ability, $model = null); /** * Check if an authority has the given roles. * - * @param \Illuminate\Database\Eloquent\Model $authority * @param array|string $roles * @param string $boolean * @return bool @@ -40,7 +36,6 @@ public function checkRole(Model $authority, $roles, $boolean = 'or'); /** * Get the given authority's roles. * - * @param \Illuminate\Database\Eloquent\Model $authority * @return \Illuminate\Support\Collection */ public function getRoles(Model $authority); @@ -48,7 +43,6 @@ public function getRoles(Model $authority); /** * Get a list of the authority's abilities. * - * @param \Illuminate\Database\Eloquent\Model $authority * @param bool $allowed * @return \Illuminate\Database\Eloquent\Collection */ @@ -57,7 +51,6 @@ public function getAbilities(Model $authority, $allowed = true); /** * Get a list of the authority's forbidden abilities. * - * @param \Illuminate\Database\Eloquent\Model $authority * @return \Illuminate\Database\Eloquent\Collection */ public function getForbiddenAbilities(Model $authority); diff --git a/src/Contracts/Scope.php b/src/Contracts/Scope.php index f6653eca..91d2aa51 100644 --- a/src/Contracts/Scope.php +++ b/src/Contracts/Scope.php @@ -18,7 +18,6 @@ public function appendToCacheKey($key); /** * Scope the given model to the current tenant. * - * @param \Illuminate\Database\Eloquent\Model $model * @return \Illuminate\Database\Eloquent\Model */ public function applyToModel(Model $model); @@ -44,7 +43,6 @@ public function applyToRelationQuery($query, $table); /** * Scope the given relation to the current tenant. * - * @param \Illuminate\Database\Eloquent\Relations\BelongsToMany $relation * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ public function applyToRelation(BelongsToMany $relation); @@ -67,8 +65,7 @@ public function getAttachAttributes($authority = null); /** * Run the given callback with the given temporary scope. * - * @param mixed $scope - * @param callable $callback + * @param mixed $scope * @return mixed */ public function onceTo($scope, callable $callback); @@ -83,7 +80,6 @@ public function remove(); /** * Run the given callback without the scope applied. * - * @param callable $callback * @return mixed */ public function removeOnce(callable $callback); diff --git a/src/Database/Ability.php b/src/Database/Ability.php index 1e26b6ab..4927f74e 100644 --- a/src/Database/Ability.php +++ b/src/Database/Ability.php @@ -28,8 +28,6 @@ class Ability extends Model /** * Constructor. - * - * @param array $attributes */ public function __construct(array $attributes = []) { diff --git a/src/Database/Concerns/HasAbilities.php b/src/Database/Concerns/HasAbilities.php index 4ad467d4..b6bdec75 100644 --- a/src/Database/Concerns/HasAbilities.php +++ b/src/Database/Concerns/HasAbilities.php @@ -3,17 +3,15 @@ namespace Silber\Bouncer\Database\Concerns; use Illuminate\Container\Container; - -use Silber\Bouncer\Helpers; -use Silber\Bouncer\Database\Models; -use Silber\Bouncer\Database\Ability; -use Silber\Bouncer\Contracts\Clipboard; -use Silber\Bouncer\Conductors\GivesAbilities; +use Illuminate\Database\Eloquent\Relations\MorphToMany; use Silber\Bouncer\Conductors\ForbidsAbilities; +use Silber\Bouncer\Conductors\GivesAbilities; use Silber\Bouncer\Conductors\RemovesAbilities; use Silber\Bouncer\Conductors\UnforbidsAbilities; - -use Illuminate\Database\Eloquent\Relations\MorphToMany; +use Silber\Bouncer\Contracts\Clipboard; +use Silber\Bouncer\Database\Ability; +use Silber\Bouncer\Database\Models; +use Silber\Bouncer\Helpers; trait HasAbilities { @@ -33,8 +31,6 @@ public static function bootHasAbilities() /** * The abilities relationship. - * - * @return \Illuminate\Database\Eloquent\Relations\MorphToMany */ public function abilities(): MorphToMany { diff --git a/src/Database/Concerns/HasRoles.php b/src/Database/Concerns/HasRoles.php index 47c45dac..5cd33c43 100644 --- a/src/Database/Concerns/HasRoles.php +++ b/src/Database/Concerns/HasRoles.php @@ -3,16 +3,14 @@ namespace Silber\Bouncer\Database\Concerns; use Illuminate\Container\Container; - -use Silber\Bouncer\Helpers; -use Silber\Bouncer\Database\Role; -use Silber\Bouncer\Database\Models; -use Silber\Bouncer\Contracts\Clipboard; +use Illuminate\Database\Eloquent\Relations\MorphToMany; use Silber\Bouncer\Conductors\AssignsRoles; use Silber\Bouncer\Conductors\RemovesRoles; +use Silber\Bouncer\Contracts\Clipboard; +use Silber\Bouncer\Database\Models; use Silber\Bouncer\Database\Queries\Roles as RolesQuery; - -use Illuminate\Database\Eloquent\Relations\MorphToMany; +use Silber\Bouncer\Database\Role; +use Silber\Bouncer\Helpers; trait HasRoles { @@ -32,8 +30,6 @@ public static function bootHasRoles() /** * The roles relationship. - * - * @return \Illuminate\Database\Eloquent\Relations\MorphToMany */ public function roles(): MorphToMany { diff --git a/src/Database/Concerns/IsAbility.php b/src/Database/Concerns/IsAbility.php index 843ae21f..1888901f 100644 --- a/src/Database/Concerns/IsAbility.php +++ b/src/Database/Concerns/IsAbility.php @@ -3,15 +3,14 @@ namespace Silber\Bouncer\Database\Concerns; use App\User; -use Silber\Bouncer\Database\Role; -use Silber\Bouncer\Database\Models; -use Silber\Bouncer\Constraints\Group; +use Illuminate\Database\Eloquent\Relations\MorphToMany; use Silber\Bouncer\Constraints\constrainer; -use Silber\Bouncer\Database\Titles\AbilityTitle; -use Silber\Bouncer\Database\Scope\TenantScope; +use Silber\Bouncer\Constraints\Group; +use Silber\Bouncer\Database\Models; use Silber\Bouncer\Database\Queries\AbilitiesForModel; - -use Illuminate\Database\Eloquent\Relations\MorphToMany; +use Silber\Bouncer\Database\Role; +use Silber\Bouncer\Database\Scope\TenantScope; +use Silber\Bouncer\Database\Titles\AbilityTitle; trait IsAbility { @@ -50,7 +49,6 @@ public function getOptionsAttribute() /** * Set the "options" attribute. * - * @param array $options * @return void */ public function setOptionsAttribute(array $options) @@ -87,7 +85,6 @@ public function getConstraints() /** * Set the ability's constraints. * - * @param \Silber\Bouncer\Constraints\Constrainer $constrainer * @return $this */ public function setConstraints(Constrainer $constrainer) @@ -140,14 +137,12 @@ public static function makeForModel($model, $attributes) return (new static)->forceFill($attributes + [ 'entity_type' => $model->getMorphClass(), - 'entity_id' => $model->exists ? $model->getKey() : null, + 'entity_id' => $model->exists ? $model->getKey() : null, ]); } /** * The roles relationship. - * - * @return \Illuminate\Database\Eloquent\Relations\MorphToMany */ public function roles(): MorphToMany { @@ -162,8 +157,6 @@ public function roles(): MorphToMany /** * The users relationship. - * - * @return \Illuminate\Database\Eloquent\Relations\MorphToMany */ public function users(): MorphToMany { @@ -214,8 +207,8 @@ public function getSlugAttribute() * Constrain a query to having the given name. * * @param \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder $query - * @return string|array $name - * @return bool $strict + * @return string|array $name + * @return bool $strict * @return void */ public function scopeByName($query, $name, $strict = false) diff --git a/src/Database/Concerns/IsRole.php b/src/Database/Concerns/IsRole.php index 18a84bee..7f783520 100644 --- a/src/Database/Concerns/IsRole.php +++ b/src/Database/Concerns/IsRole.php @@ -2,22 +2,20 @@ namespace Silber\Bouncer\Database\Concerns; -use Silber\Bouncer\Helpers; -use Silber\Bouncer\Database\Models; -use Silber\Bouncer\Database\Titles\RoleTitle; -use Silber\Bouncer\Database\Scope\TenantScope; -use Silber\Bouncer\Database\Queries\Roles as RolesQuery; - use App\User; -use Illuminate\Support\Arr; -use InvalidArgumentException; -use Illuminate\Support\Collection; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphToMany; +use Illuminate\Support\Arr; +use Illuminate\Support\Collection; +use Silber\Bouncer\Database\Models; +use Silber\Bouncer\Database\Queries\Roles as RolesQuery; +use Silber\Bouncer\Database\Scope\TenantScope; +use Silber\Bouncer\Database\Titles\RoleTitle; +use Silber\Bouncer\Helpers; trait IsRole { - use HasAbilities, Authorizable; + use Authorizable, HasAbilities; /** * Boot the is role trait. @@ -61,12 +59,11 @@ public function users(): MorphToMany * Assign the role to the given model(s). * * @param string|\Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection $model - * @param array|null $keys * @return $this */ - public function assignTo($model, array $keys = null) + public function assignTo($model, ?array $keys = null) { - list($model, $keys) = Helpers::extractModelAndKeys($model, $keys); + [$model, $keys] = Helpers::extractModelAndKeys($model, $keys); $query = $this->newBaseQueryBuilder()->from(Models::table('assigned_roles')); @@ -107,11 +104,11 @@ protected function findOrCreateRolesByName($names) $existing = static::whereIn('name', $names)->get()->keyBy('name'); return (new Collection($names)) - ->diff($existing->pluck('name')) - ->map(function ($name) { - return static::create(compact('name')); - }) - ->merge($existing); + ->diff($existing->pluck('name')) + ->map(function ($name) { + return static::create(compact('name')); + }) + ->merge($existing); } /** @@ -161,8 +158,8 @@ public function getKeysByName($names) } return $this->whereIn('name', $names) - ->select($this->getKeyName())->get() - ->pluck($this->getKeyName())->all(); + ->select($this->getKeyName())->get() + ->pluck($this->getKeyName())->all(); } /** @@ -178,20 +175,19 @@ public function getNamesByKey($keys) } return $this->whereIn($this->getKeyName(), $keys) - ->select('name')->get() - ->pluck('name')->all(); + ->select('name')->get() + ->pluck('name')->all(); } /** * Retract the role from the given model(s). * * @param string|\Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection $model - * @param array|null $keys * @return $this */ - public function retractFrom($model, array $keys = null) + public function retractFrom($model, ?array $keys = null) { - list($model, $keys) = Helpers::extractModelAndKeys($model, $keys); + [$model, $keys] = Helpers::extractModelAndKeys($model, $keys); $query = $this->newBaseQueryBuilder() ->from(Models::table('assigned_roles')) @@ -209,8 +205,6 @@ public function retractFrom($model, array $keys = null) /** * Create the pivot table records for assigning the role to given models. * - * @param \Illuminate\Database\Eloquent\Model $model - * @param array $keys * @return array */ protected function createAssignRecords(Model $model, array $keys) @@ -219,9 +213,9 @@ protected function createAssignRecords(Model $model, array $keys) return array_map(function ($key) use ($type) { return Models::scope()->getAttachAttributes() + [ - 'role_id' => $this->getKey(), + 'role_id' => $this->getKey(), 'entity_type' => $type, - 'entity_id' => $key, + 'entity_id' => $key, ]; }, $keys); } @@ -231,10 +225,9 @@ protected function createAssignRecords(Model $model, array $keys) * * @param \Illuminate\Database\Eloquent\Builder $query * @param string|\Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection $model - * @param array $keys * @return void */ - public function scopeWhereAssignedTo($query, $model, array $keys = null) + public function scopeWhereAssignedTo($query, $model, ?array $keys = null) { (new RolesQuery)->constrainWhereAssignedTo($query, $model, $keys); } diff --git a/src/Database/HasRolesAndAbilities.php b/src/Database/HasRolesAndAbilities.php index a5648295..2b07ed33 100644 --- a/src/Database/HasRolesAndAbilities.php +++ b/src/Database/HasRolesAndAbilities.php @@ -2,10 +2,10 @@ namespace Silber\Bouncer\Database; -use Silber\Bouncer\Database\Concerns\HasRoles; use Silber\Bouncer\Database\Concerns\HasAbilities; +use Silber\Bouncer\Database\Concerns\HasRoles; trait HasRolesAndAbilities { - use HasRoles, HasAbilities; + use HasAbilities, HasRoles; } diff --git a/src/Database/Models.php b/src/Database/Models.php index 1455011b..710ac7fb 100644 --- a/src/Database/Models.php +++ b/src/Database/Models.php @@ -2,14 +2,13 @@ namespace Silber\Bouncer\Database; -use Closure; use App\User; -use Illuminate\Database\Query\Builder; +use Closure; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\Relation; - -use Silber\Bouncer\Database\Scope\Scope; +use Illuminate\Database\Query\Builder; use Silber\Bouncer\Contracts\Scope as ScopeContract; +use Silber\Bouncer\Database\Scope\Scope; class Models { @@ -83,7 +82,6 @@ public static function setUsersModel($model) /** * Set custom table names. * - * @param array $map * @return void */ public static function setTables(array $map) @@ -111,10 +109,9 @@ public static function table($table) /** * Get or set the model scoping instance. * - * @param \Silber\Bouncer\Contracts\Scope|null $scope * @return mixed */ - public static function scope(ScopeContract $scope = null) + public static function scope(?ScopeContract $scope = null) { if (! is_null($scope)) { return static::$scope = $scope; @@ -179,8 +176,6 @@ public static function ownedVia($model, $attribute = null) /** * Determines whether the given model is owned by the given authority. * - * @param \Illuminate\Database\Eloquent\Model $authority - * @param \Illuminate\Database\Eloquent\Model $model * @return bool */ public static function isOwnedBy(Model $authority, Model $model) @@ -202,8 +197,6 @@ public static function isOwnedBy(Model $authority, Model $model) * Determines ownership via the given attribute. * * @param string|\Closure $attribute - * @param \Illuminate\Database\Eloquent\Model $authority - * @param \Illuminate\Database\Eloquent\Model $model * @return bool */ protected static function isOwnedVia($attribute, Model $authority, Model $model) @@ -218,7 +211,6 @@ protected static function isOwnedVia($attribute, Model $authority, Model $model) /** * Get an instance of the ability model. * - * @param array $attributes * @return \Silber\Bouncer\Database\Ability */ public static function ability(array $attributes = []) @@ -229,7 +221,6 @@ public static function ability(array $attributes = []) /** * Get an instance of the role model. * - * @param array $attributes * @return \Silber\Bouncer\Database\Role */ public static function role(array $attributes = []) @@ -240,7 +231,6 @@ public static function role(array $attributes = []) /** * Get an instance of the user model. * - * @param array $attributes * @return \Illuminate\Database\Eloquent\Model */ public static function user(array $attributes = []) @@ -279,7 +269,6 @@ public static function reset() * Get an instance of the given model. * * @param string $model - * @param array $attributes * @return \Illuminate\Database\Eloquent\Model */ protected static function make($model, array $attributes = []) @@ -297,7 +286,7 @@ protected static function make($model, array $attributes = []) */ protected static function basename($class) { - if ( ! is_string($class)) { + if (! is_string($class)) { $class = get_class($class); } diff --git a/src/Database/Queries/Abilities.php b/src/Database/Queries/Abilities.php index 2f98d93d..d02af089 100644 --- a/src/Database/Queries/Abilities.php +++ b/src/Database/Queries/Abilities.php @@ -2,17 +2,14 @@ namespace Silber\Bouncer\Database\Queries; -use Silber\Bouncer\Database\Models; - -use Illuminate\Database\Query\Builder; use Illuminate\Database\Eloquent\Model; +use Silber\Bouncer\Database\Models; class Abilities { /** * Get a query for the authority's abilities. * - * @param \Illuminate\Database\Eloquent\Model $authority * @param bool $allowed * @return \Illuminate\Database\Eloquent\Builder */ @@ -28,7 +25,6 @@ public static function forAuthority(Model $authority, $allowed = true) /** * Get a query for the authority's forbidden abilities. * - * @param \Illuminate\Database\Eloquent\Model $authority * @return \Illuminate\Database\Eloquent\Builder */ public static function forbiddenForAuthority(Model $authority) @@ -39,7 +35,6 @@ public static function forbiddenForAuthority(Model $authority) /** * Get a constraint for abilities that have been granted to the given authority through a role. * - * @param \Illuminate\Database\Eloquent\Model $authority * @param bool $allowed * @return \Closure */ @@ -47,19 +42,19 @@ protected static function getRoleConstraint(Model $authority, $allowed) { return function ($query) use ($authority, $allowed) { $permissions = Models::table('permissions'); - $abilities = Models::table('abilities'); - $roles = Models::table('roles'); + $abilities = Models::table('abilities'); + $roles = Models::table('roles'); $query->from($roles) - ->join($permissions, $roles.'.id', '=', $permissions.'.entity_id') - ->whereColumn("{$permissions}.ability_id", "{$abilities}.id") - ->where($permissions.".forbidden", ! $allowed) - ->where($permissions.".entity_type", Models::role()->getMorphClass()); + ->join($permissions, $roles.'.id', '=', $permissions.'.entity_id') + ->whereColumn("{$permissions}.ability_id", "{$abilities}.id") + ->where($permissions.'.forbidden', ! $allowed) + ->where($permissions.'.entity_type', Models::role()->getMorphClass()); Models::scope()->applyToModelQuery($query, $roles); Models::scope()->applyToRelationQuery($query, $permissions); - $query->where(function ($query) use ($roles, $authority, $allowed) { + $query->where(function ($query) use ($authority) { $query->whereExists(static::getAuthorityRoleConstraint($authority)); }); }; @@ -68,21 +63,20 @@ protected static function getRoleConstraint(Model $authority, $allowed) /** * Get a constraint for roles that are assigned to the given authority. * - * @param \Illuminate\Database\Eloquent\Model $authority * @return \Closure */ protected static function getAuthorityRoleConstraint(Model $authority) { return function ($query) use ($authority) { - $pivot = Models::table('assigned_roles'); - $roles = Models::table('roles'); - $table = $authority->getTable(); + $pivot = Models::table('assigned_roles'); + $roles = Models::table('roles'); + $table = $authority->getTable(); $query->from($table) - ->join($pivot, "{$table}.{$authority->getKeyName()}", '=', $pivot.'.entity_id') - ->whereColumn("{$pivot}.role_id", "{$roles}.id") - ->where($pivot.'.entity_type', $authority->getMorphClass()) - ->where("{$table}.{$authority->getKeyName()}", $authority->getKey()); + ->join($pivot, "{$table}.{$authority->getKeyName()}", '=', $pivot.'.entity_id') + ->whereColumn("{$pivot}.role_id", "{$roles}.id") + ->where($pivot.'.entity_type', $authority->getMorphClass()) + ->where("{$table}.{$authority->getKeyName()}", $authority->getKey()); Models::scope()->applyToModelQuery($query, $roles); Models::scope()->applyToRelationQuery($query, $pivot); @@ -92,7 +86,6 @@ protected static function getAuthorityRoleConstraint(Model $authority) /** * Get a constraint for abilities that have been granted to the given authority. * - * @param \Illuminate\Database\Eloquent\Model $authority * @param bool $allowed * @return \Closure */ @@ -100,15 +93,15 @@ protected static function getAuthorityConstraint(Model $authority, $allowed) { return function ($query) use ($authority, $allowed) { $permissions = Models::table('permissions'); - $abilities = Models::table('abilities'); - $table = $authority->getTable(); + $abilities = Models::table('abilities'); + $table = $authority->getTable(); $query->from($table) - ->join($permissions, "{$table}.{$authority->getKeyName()}", '=', $permissions.'.entity_id') - ->whereColumn("{$permissions}.ability_id", "{$abilities}.id") - ->where("{$permissions}.forbidden", ! $allowed) - ->where("{$permissions}.entity_type", $authority->getMorphClass()) - ->where("{$table}.{$authority->getKeyName()}", $authority->getKey()); + ->join($permissions, "{$table}.{$authority->getKeyName()}", '=', $permissions.'.entity_id') + ->whereColumn("{$permissions}.ability_id", "{$abilities}.id") + ->where("{$permissions}.forbidden", ! $allowed) + ->where("{$permissions}.entity_type", $authority->getMorphClass()) + ->where("{$table}.{$authority->getKeyName()}", $authority->getKey()); Models::scope()->applyToModelQuery($query, $abilities); Models::scope()->applyToRelationQuery($query, $permissions); @@ -125,12 +118,12 @@ protected static function getEveryoneConstraint($allowed) { return function ($query) use ($allowed) { $permissions = Models::table('permissions'); - $abilities = Models::table('abilities'); + $abilities = Models::table('abilities'); $query->from($permissions) - ->whereColumn("{$permissions}.ability_id", "{$abilities}.id") - ->where("{$permissions}.forbidden", ! $allowed) - ->whereNull('entity_id'); + ->whereColumn("{$permissions}.ability_id", "{$abilities}.id") + ->where("{$permissions}.forbidden", ! $allowed) + ->whereNull('entity_id'); Models::scope()->applyToRelationQuery($query, $permissions); }; diff --git a/src/Database/Queries/AbilitiesForModel.php b/src/Database/Queries/AbilitiesForModel.php index 5b2a1746..c36b73a4 100644 --- a/src/Database/Queries/AbilitiesForModel.php +++ b/src/Database/Queries/AbilitiesForModel.php @@ -2,8 +2,8 @@ namespace Silber\Bouncer\Database\Queries; -use Silber\Bouncer\Database\Models; use Illuminate\Database\Eloquent\Model; +use Silber\Bouncer\Database\Models; class AbilitiesForModel { @@ -16,7 +16,6 @@ class AbilitiesForModel /** * Constructor. - * */ public function __construct() { @@ -57,7 +56,6 @@ protected function constrainByWildcard($query) * Constrain a query to an ability for a specific model. * * @param \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder $query - * @param \Illuminate\Database\Eloquent\Model $model * @param bool $strict * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder */ @@ -71,14 +69,13 @@ protected function constrainByModel($query, Model $model, $strict) return $query->where(function ($query) use ($model, $strict) { $query->where("{$this->table}.entity_type", '*') - ->orWhere($this->modelAbilityConstraint($model, $strict)); + ->orWhere($this->modelAbilityConstraint($model, $strict)); }); } /** * Get the constraint for regular model abilities. * - * @param \Illuminate\Database\Eloquent\Model $model * @param bool $strict * @return \Closure */ @@ -94,7 +91,6 @@ protected function modelAbilityConstraint(Model $model, $strict) /** * Get the constraint for the ability subquery. * - * @param \Illuminate\Database\Eloquent\Model $model * @param bool $strict * @return \Closure */ @@ -104,7 +100,7 @@ protected function abilitySubqueryConstraint(Model $model, $strict) // If the model does not exist, we want to search for blanket abilities // that cover all instances of this model. If it does exist, we only // want to find blanket abilities if we're not using strict mode. - if ( ! $model->exists || ! $strict) { + if (! $model->exists || ! $strict) { $query->whereNull("{$this->table}.entity_id"); } diff --git a/src/Database/Queries/Roles.php b/src/Database/Queries/Roles.php index 4f15bb3b..7c06a820 100644 --- a/src/Database/Queries/Roles.php +++ b/src/Database/Queries/Roles.php @@ -2,8 +2,8 @@ namespace Silber\Bouncer\Database\Queries; -use Silber\Bouncer\Helpers; use Silber\Bouncer\Database\Models; +use Silber\Bouncer\Helpers; class Roles { @@ -54,24 +54,23 @@ public function constrainWhereIsNot($query, ...$roles) * * @param \Illuminate\Database\Eloquent\Builder $query * @param string|\Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection $model - * @param array $keys * @return void */ - public function constrainWhereAssignedTo($query, $model, array $keys = null) + public function constrainWhereAssignedTo($query, $model, ?array $keys = null) { - list($model, $keys) = Helpers::extractModelAndKeys($model, $keys); + [$model, $keys] = Helpers::extractModelAndKeys($model, $keys); $query->whereExists(function ($query) use ($model, $keys) { - $table = $model->getTable(); - $key = "{$table}.{$model->getKeyName()}"; - $pivot = Models::table('assigned_roles'); - $roles = Models::table('roles'); + $table = $model->getTable(); + $key = "{$table}.{$model->getKeyName()}"; + $pivot = Models::table('assigned_roles'); + $roles = Models::table('roles'); $query->from($table) - ->join($pivot, $key, '=', $pivot.'.entity_id') - ->whereColumn("{$pivot}.role_id", "{$roles}.id") - ->where("{$pivot}.entity_type", $model->getMorphClass()) - ->whereIn($key, $keys); + ->join($pivot, $key, '=', $pivot.'.entity_id') + ->whereColumn("{$pivot}.role_id", "{$roles}.id") + ->where("{$pivot}.entity_type", $model->getMorphClass()) + ->whereIn($key, $keys); Models::scope()->applyToModelQuery($query, $roles); Models::scope()->applyToRelationQuery($query, $pivot); diff --git a/src/Database/Role.php b/src/Database/Role.php index 8943e44c..b4ca73c6 100644 --- a/src/Database/Role.php +++ b/src/Database/Role.php @@ -26,8 +26,6 @@ class Role extends Model /** * Constructor. - * - * @param array $attributes */ public function __construct(array $attributes = []) { diff --git a/src/Database/Scope/Scope.php b/src/Database/Scope/Scope.php index 7e7edd23..0c29346c 100644 --- a/src/Database/Scope/Scope.php +++ b/src/Database/Scope/Scope.php @@ -2,12 +2,11 @@ namespace Silber\Bouncer\Database\Scope; -use Silber\Bouncer\Database\Role; -use Silber\Bouncer\Database\Models; -use Silber\Bouncer\Contracts\Scope as ScopeContract; - use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Silber\Bouncer\Contracts\Scope as ScopeContract; +use Silber\Bouncer\Database\Models; +use Silber\Bouncer\Database\Role; class Scope implements ScopeContract { @@ -88,7 +87,6 @@ public function appendToCacheKey($key) /** * Scope the given model to the current tenant. * - * @param \Illuminate\Database\Eloquent\Model $model * @return \Illuminate\Database\Eloquent\Model */ public function applyToModel(Model $model) @@ -135,7 +133,6 @@ public function applyToRelationQuery($query, $table) /** * Scope the given relation to the current tenant. * - * @param \Illuminate\Database\Eloquent\Relations\BelongsToMany $relation * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ public function applyToRelation(BelongsToMany $relation) @@ -202,8 +199,7 @@ public function getAttachAttributes($authority = null) /** * Run the given callback with the given temporary scope. * - * @param mixed $scope - * @param callable $callback + * @param mixed $scope * @return mixed */ public function onceTo($scope, callable $callback) @@ -232,7 +228,6 @@ public function remove() /** * Run the given callback without the scope applied. * - * @param callable $callback * @return mixed */ public function removeOnce(callable $callback) @@ -243,7 +238,7 @@ public function removeOnce(callable $callback) /** * Determine whether the given class name is the role model. * - * @param string|null $className + * @param string|null $className * @return bool */ protected function isRoleClass($className) diff --git a/src/Database/Scope/TenantScope.php b/src/Database/Scope/TenantScope.php index 62a66816..d4b3acf8 100644 --- a/src/Database/Scope/TenantScope.php +++ b/src/Database/Scope/TenantScope.php @@ -2,11 +2,10 @@ namespace Silber\Bouncer\Database\Scope; -use Illuminate\Support\Collection; -use Silber\Bouncer\Database\Models; -use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Scope as EloquentScope; +use Silber\Bouncer\Database\Models; class TenantScope implements EloquentScope { @@ -24,8 +23,6 @@ public static function register($model) /** * Apply the scope to a given Eloquent query builder. * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param \Illuminate\Database\Eloquent\Model $model * @return void */ public function apply(Builder $query, Model $model) diff --git a/src/Database/Titles/AbilityTitle.php b/src/Database/Titles/AbilityTitle.php index 5409091b..bee60a2d 100644 --- a/src/Database/Titles/AbilityTitle.php +++ b/src/Database/Titles/AbilityTitle.php @@ -2,33 +2,31 @@ namespace Silber\Bouncer\Database\Titles; -use Illuminate\Support\Str; use Illuminate\Database\Eloquent\model; +use Illuminate\Support\Str; class AbilityTitle extends Title { /** * Constructor. - * - * @param \Illuminate\Database\Eloquent\model $ability */ public function __construct(Model $ability) { if ($this->isWildcardAbility($ability)) { $this->title = $this->getWildcardAbilityTitle($ability); - } else if ($this->isRestrictedWildcardAbility($ability)) { + } elseif ($this->isRestrictedWildcardAbility($ability)) { $this->title = 'All simple abilities'; - } else if ($this->isSimpleAbility($ability)) { + } elseif ($this->isSimpleAbility($ability)) { $this->title = $this->humanize($ability->name); - } else if ($this->isRestrictedOwnershipAbility($ability)) { + } elseif ($this->isRestrictedOwnershipAbility($ability)) { $this->title = $this->humanize($ability->name.' everything owned'); - } else if ($this->isGeneralManagementAbility($ability)) { + } elseif ($this->isGeneralManagementAbility($ability)) { $this->title = $this->getBlanketModelAbilityTitle($ability); - } else if ($this->isBlanketModelAbility($ability)) { + } elseif ($this->isBlanketModelAbility($ability)) { $this->title = $this->getBlanketModelAbilityTitle($ability, $ability->name); - } else if ($this->isSpecificModelAbility($ability)) { + } elseif ($this->isSpecificModelAbility($ability)) { $this->title = $this->getSpecificModelAbilityTitle($ability); - } else if ($this->isGlobalActionAbility($ability)) { + } elseif ($this->isGlobalActionAbility($ability)) { $this->title = $this->humanize($ability->name.' everything'); } } @@ -36,7 +34,6 @@ public function __construct(Model $ability) /** * Determines if the given ability allows all abilities. * - * @param \Illuminate\Database\Eloquent\model $ability * @return bool */ protected function isWildcardAbility(Model $ability) @@ -47,7 +44,6 @@ protected function isWildcardAbility(Model $ability) /** * Determines if the given ability allows all simple abilities. * - * @param \Illuminate\Database\Eloquent\model $ability * @return bool */ protected function isRestrictedWildcardAbility(Model $ability) @@ -58,7 +54,6 @@ protected function isRestrictedWildcardAbility(Model $ability) /** * Determines if the given ability is a simple (non model) ability. * - * @param \Illuminate\Database\Eloquent\model $ability * @return bool */ protected function isSimpleAbility(Model $ability) @@ -70,7 +65,6 @@ protected function isSimpleAbility(Model $ability) * Determines whether the given ability is a global * ownership ability restricted to a specific action. * - * @param \Illuminate\Database\Eloquent\model $ability * @return bool */ protected function isRestrictedOwnershipAbility(Model $ability) @@ -81,7 +75,6 @@ protected function isRestrictedOwnershipAbility(Model $ability) /** * Determines whether the given ability is for managing all models of a given type. * - * @param \Illuminate\Database\Eloquent\model $ability * @return bool */ protected function isGeneralManagementAbility(Model $ability) @@ -95,7 +88,6 @@ protected function isGeneralManagementAbility(Model $ability) /** * Determines whether the given ability is for an action on all models of a given type. * - * @param \Illuminate\Database\Eloquent\model $ability * @return bool */ protected function isBlanketModelAbility(Model $ability) @@ -109,7 +101,6 @@ protected function isBlanketModelAbility(Model $ability) /** * Determines whether the given ability is for an action on a specific model. * - * @param \Illuminate\Database\Eloquent\model $ability * @return bool */ protected function isSpecificModelAbility(Model $ability) @@ -122,7 +113,6 @@ protected function isSpecificModelAbility(Model $ability) /** * Determines whether the given ability allows an action on all models. * - * @param \Illuminate\Database\Eloquent\model $ability * @return bool */ protected function isGlobalActionAbility(Model $ability) @@ -135,7 +125,6 @@ protected function isGlobalActionAbility(Model $ability) /** * Get the title for the given wildcard ability. * - * @param \Illuminate\Database\Eloquent\model $ability * @return string */ protected function getWildcardAbilityTitle(Model $ability) @@ -150,7 +139,6 @@ protected function getWildcardAbilityTitle(Model $ability) /** * Get the title for the given blanket model ability. * - * @param \Illuminate\Database\Eloquent\model $ability * @param string $name * @return string */ @@ -162,7 +150,6 @@ protected function getBlanketModelAbilityTitle(Model $ability, $name = 'manage') /** * Get the title for the given model ability. * - * @param \Illuminate\Database\Eloquent\model $ability * @return string */ protected function getSpecificModelAbilityTitle(Model $ability) diff --git a/src/Database/Titles/Title.php b/src/Database/Titles/Title.php index 8c197804..b3b1aea9 100644 --- a/src/Database/Titles/Title.php +++ b/src/Database/Titles/Title.php @@ -2,8 +2,8 @@ namespace Silber\Bouncer\Database\Titles; -use Illuminate\Support\Str; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Str; abstract class Title { @@ -17,7 +17,6 @@ abstract class Title /** * Create a new title instance for the given model. * - * @param \Illuminate\Database\Eloquent\Model $model * @return static */ public static function from(Model $model) diff --git a/src/Factory.php b/src/Factory.php index 5a94e856..d9377a0c 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -5,8 +5,8 @@ use Illuminate\Auth\Access\Gate; use Illuminate\Cache\ArrayStore; use Illuminate\Container\Container; -use Illuminate\Contracts\Cache\Store; use Illuminate\Contracts\Auth\Access\Gate as GateContract; +use Illuminate\Contracts\Cache\Store; class Factory { @@ -55,7 +55,7 @@ class Factory /** * Create a new Factory instance. * - * @param mixed $user + * @param mixed $user */ public function __construct($user = null) { @@ -88,7 +88,6 @@ public function create() /** * Set the cache instance to use for the clipboard. * - * @param \Illuminate\Contracts\Cache\Store $cache * @return $this */ public function withCache(Store $cache) @@ -101,7 +100,6 @@ public function withCache(Store $cache) /** * Set the instance of the clipboard to use. * - * @param \Silber\Bouncer\Contracts\Clipboard $clipboard * @return $this */ public function withClipboard(Contracts\Clipboard $clipboard) @@ -114,7 +112,6 @@ public function withClipboard(Contracts\Clipboard $clipboard) /** * Set the gate instance to use. * - * @param \Illuminate\Contracts\Auth\Access\Gate $gate * @return $this */ public function withGate(GateContract $gate) diff --git a/src/Guard.php b/src/Guard.php index 04ddba22..c4751c1b 100644 --- a/src/Guard.php +++ b/src/Guard.php @@ -2,10 +2,10 @@ namespace Silber\Bouncer; -use InvalidArgumentException; -use Illuminate\Database\Eloquent\Model; -use Illuminate\Contracts\Auth\Access\Gate; use Illuminate\Auth\Access\HandlesAuthorization; +use Illuminate\Contracts\Auth\Access\Gate; +use Illuminate\Database\Eloquent\Model; +use InvalidArgumentException; class Guard { @@ -29,8 +29,6 @@ class Guard /** * Create a new guard instance. - * - * @param \Silber\Bouncer\Contracts\Clipboard $clipboard */ public function __construct(Contracts\Clipboard $clipboard) { @@ -50,7 +48,6 @@ public function getClipboard() /** * Set the clipboard instance. * - * @param \Silber\Bouncer\Contracts\Clipboard $clipboard * @return $this */ public function setClipboard(Contracts\Clipboard $clipboard) @@ -96,7 +93,6 @@ public function slot($slot = null) /** * Register the clipboard at the given gate. * - * @param \Illuminate\Contracts\Auth\Access\Gate $gate * @return $this */ public function registerAt(Gate $gate) @@ -167,7 +163,6 @@ protected function runAfterCallback($authority, $ability, $result, $arguments = /** * Run an auth check at the clipboard. * - * @param \Illuminate\Database\Eloquent\Model $authority * @param string $ability * @param \Illuminate\Database\Eloquent\Model|string|null $model * @return mixed diff --git a/src/Helpers.php b/src/Helpers.php index 79ccf5d7..8cf12df9 100644 --- a/src/Helpers.php +++ b/src/Helpers.php @@ -2,12 +2,11 @@ namespace Silber\Bouncer; -use Silber\Bouncer\Database\Models; - use App\User; -use InvalidArgumentException; -use Illuminate\Support\Collection; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Collection; +use InvalidArgumentException; +use Silber\Bouncer\Database\Models; class Helpers { @@ -32,10 +31,9 @@ public static function ensureValidLogicalOperator($operator) * Extract the model instance and model keys from the given parameters. * * @param \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|string $model - * @param array|null $keys * @return array */ - public static function extractModelAndKeys($model, array $keys = null) + public static function extractModelAndKeys($model, ?array $keys = null) { if (! is_null($keys)) { if (is_string($model)) { @@ -88,9 +86,9 @@ public static function groupModelsAndIdentifiersByType($models) $groups = (new Collection($models))->groupBy(function ($model) { if (is_numeric($model)) { return 'integers'; - } else if (is_string($model)) { + } elseif (is_string($model)) { return 'strings'; - } else if ($model instanceof Model) { + } elseif ($model instanceof Model) { return 'models'; } @@ -145,7 +143,6 @@ public static function isIndexedArray($array) /** * Determines whether the given model is set to soft delete. * - * @param \Illuminate\Database\Eloquent\Model $model * @return bool */ public static function isSoftDeleting(Model $model) @@ -182,7 +179,6 @@ public static function toArray($value) /** * Map a list of authorities by their class name. * - * @param array $authorities * @return array */ public static function mapAuthorityByClass(array $authorities) @@ -204,7 +200,6 @@ public static function mapAuthorityByClass(array $authorities) * Partition the given collection into two collection using the given callback. * * @param iterable $items - * @param callable $callback * @return \Illuminate\Support\Collection */ public static function partition($items, callable $callback) diff --git a/tests/AbilitiesForModelsTest.php b/tests/AbilitiesForModelsTest.php index 80a8d56c..4e59c0d2 100644 --- a/tests/AbilitiesForModelsTest.php +++ b/tests/AbilitiesForModelsTest.php @@ -2,13 +2,11 @@ namespace Silber\Bouncer\Tests; -use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\DataProvider; - +use PHPUnit\Framework\Attributes\Test; use Silber\Bouncer\Database\Ability; -use Illuminate\Database\Eloquent\Model; -use Workbench\App\Models\User; use Workbench\App\Models\Account; +use Workbench\App\Models\User; class AbilitiesForModelsTest extends BaseTestCase { diff --git a/tests/AbilityConstraintsTest.php b/tests/AbilityConstraintsTest.php index 4249ed44..bfb030dd 100644 --- a/tests/AbilityConstraintsTest.php +++ b/tests/AbilityConstraintsTest.php @@ -3,13 +3,11 @@ namespace Silber\Bouncer\Tests; use PHPUnit\Framework\Attributes\Test; -use PHPUnit\Framework\Attributes\DataProvider; - -use Silber\Bouncer\Database\Ability; -use Silber\Bouncer\Constraints\Group; use Silber\Bouncer\Constraints\Constraint; -use Workbench\App\Models\User; +use Silber\Bouncer\Constraints\Group; +use Silber\Bouncer\Database\Ability; use Workbench\App\Models\Account; +use Workbench\App\Models\User; class AbilityConstraintsTest extends BaseTestCase { @@ -39,7 +37,7 @@ public function can_set_and_get_constraints() { $ability = Ability::makeForModel(Account::class, '*')->setConstraints( new Group([ - Constraint::where('active', true) + Constraint::where('active', true), ]) ); diff --git a/tests/AuthorizableTest.php b/tests/AuthorizableTest.php index 7af0ad82..23b80c19 100644 --- a/tests/AuthorizableTest.php +++ b/tests/AuthorizableTest.php @@ -2,12 +2,11 @@ namespace Silber\Bouncer\Tests; -use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\DataProvider; - +use PHPUnit\Framework\Attributes\Test; use Silber\Bouncer\Database\Role; -use Workbench\App\Models\User; use Workbench\App\Models\Account; +use Workbench\App\Models\User; class AuthorizableTest extends BaseTestCase { diff --git a/tests/AutoTitlesTest.php b/tests/AutoTitlesTest.php index 6cd68e50..80b7123e 100644 --- a/tests/AutoTitlesTest.php +++ b/tests/AutoTitlesTest.php @@ -3,12 +3,8 @@ namespace Silber\Bouncer\Tests; use PHPUnit\Framework\Attributes\Test; -use PHPUnit\Framework\Attributes\DataProvider; - use Silber\Bouncer\Database\Role; -use Silber\Bouncer\Database\Ability; use Workbench\App\Models\User; -use Workbench\App\Models\Account; class AutoTitlesTest extends BaseTestCase { diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index cd9edaff..ec6c16d3 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -2,26 +2,22 @@ namespace Silber\Bouncer\Tests; -use PHPUnit\Framework\Attributes\Test; -use PHPUnit\Framework\Attributes\DataProvider; - -use function Orchestra\Testbench\artisan; -use function Orchestra\Testbench\workbench_path; -use function Orchestra\Testbench\package_path; - -use Silber\Bouncer\Database\Models; -use Workbench\App\Models\User; +use Illuminate\Auth\Access\Gate; +use Illuminate\Container\Container; use Illuminate\Database\DatabaseManager; -use Silber\Bouncer\Guard; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Foundation\Testing\RefreshDatabase; +use Orchestra\Testbench\TestCase; use Silber\Bouncer\Bouncer; use Silber\Bouncer\Clipboard; use Silber\Bouncer\Contracts\Clipboard as ClipboardContract; -use Illuminate\Foundation\Testing\RefreshDatabase; +use Silber\Bouncer\Database\Models; +use Silber\Bouncer\Guard; +use Workbench\App\Models\User; -use Illuminate\Auth\Access\Gate; -use Illuminate\Container\Container; -use Illuminate\Database\Eloquent\Model; -use Orchestra\Testbench\TestCase; +use function Orchestra\Testbench\artisan; +use function Orchestra\Testbench\package_path; +use function Orchestra\Testbench\workbench_path; abstract class BaseTestCase extends TestCase { @@ -33,7 +29,7 @@ abstract class BaseTestCase extends TestCase public function setUp(): void { parent::setUp(); - + Models::setUsersModel(User::class); static::registerClipboard(); @@ -72,7 +68,7 @@ protected static function makeClipboard(): ClipboardContract /** * Get a bouncer instance. */ - protected static function bouncer(Model $authority = null): Bouncer + protected static function bouncer(?Model $authority = null): Bouncer { $gate = static::gate($authority ?: User::create()); diff --git a/tests/BeforePoliciesTest.php b/tests/BeforePoliciesTest.php index 2ce3415e..56fd7b48 100644 --- a/tests/BeforePoliciesTest.php +++ b/tests/BeforePoliciesTest.php @@ -2,14 +2,9 @@ namespace Silber\Bouncer\Tests; -use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\DataProvider; - +use PHPUnit\Framework\Attributes\Test; use Silber\Bouncer\Bouncer; -use Illuminate\Auth\Access\Gate; -use Silber\Bouncer\Database\Role; -use Silber\Bouncer\Database\Ability; -use Workbench\App\Models\User; use Workbench\App\Models\Account; class BeforePoliciesTest extends BaseTestCase @@ -93,7 +88,7 @@ public function fails_auth_check_when_bouncer_does_not_allow($provider) /** * Set up the given Bouncer instance with the test policy. * - * @param \Silber\Buoncer\Bouncer $bouncer + * @param \Silber\Buoncer\Bouncer $bouncer */ protected function setUpWithPolicy(Bouncer $bouncer) { diff --git a/tests/BouncerSimpleTest.php b/tests/BouncerSimpleTest.php index cd207d73..fb2bf9b4 100644 --- a/tests/BouncerSimpleTest.php +++ b/tests/BouncerSimpleTest.php @@ -2,14 +2,13 @@ namespace Silber\Bouncer\Tests; -use PHPUnit\Framework\Attributes\Test; -use PHPUnit\Framework\Attributes\DataProvider; - use Exception; -use Silber\Bouncer\Database\Role; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Silber\Bouncer\Database\Ability; -use Workbench\App\Models\User; +use Silber\Bouncer\Database\Role; use Workbench\App\Models\Account; +use Workbench\App\Models\User; class BouncerSimpleTest extends BaseTestCase { @@ -41,7 +40,6 @@ public function can_give_and_remove_abilities($provider) $this->assertTrue($bouncer->cannot('access-dashboard')); } - #[Test] #[DataProvider('bouncerProvider')] public function can_give_and_remove_abilities_for_everyone($provider) @@ -156,8 +154,8 @@ public function can_give_and_remove_multiple_roles_at_once($provider) { [$bouncer, $user] = $provider(); - $admin = $this->role('admin'); - $editor = $this->role('editor'); + $admin = $this->role('admin'); + $editor = $this->role('editor'); $reviewer = $this->role('reviewer'); $bouncer->assign(collect([$admin, 'editor', $reviewer->id]))->to($user); @@ -312,7 +310,7 @@ public function can_allow_abilities_from_a_defined_callback($provider) [$bouncer, $user] = $provider(); $bouncer->define('edit', function ($user, $account) { - if ( ! $account instanceof Account) { + if (! $account instanceof Account) { return null; } diff --git a/tests/CachedClipboardTest.php b/tests/CachedClipboardTest.php index b8f8857e..b07c190d 100644 --- a/tests/CachedClipboardTest.php +++ b/tests/CachedClipboardTest.php @@ -2,16 +2,13 @@ namespace Silber\Bouncer\Tests; +use Illuminate\Cache\ArrayStore; +use Illuminate\Database\Eloquent\Collection; +use Illuminate\Database\Eloquent\Model; use PHPUnit\Framework\Attributes\Test; -use PHPUnit\Framework\Attributes\DataProvider; - use Silber\Bouncer\CachedClipboard; use Silber\Bouncer\Contracts\Clipboard as ClipboardContract; -use Illuminate\Cache\ArrayStore; -use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Collection; use Workbench\App\Models\User; -use Workbench\App\Models\Account; class CachedClipboardTest extends BaseTestCase { @@ -129,7 +126,6 @@ public function it_can_refresh_the_cache_only_for_one_user() /** * Get the name of all of the user's abilities. * - * @param \Illuminate\Database\Eloquent\Model $user * @return array */ protected function getAbilities(Model $user) diff --git a/tests/CleanCommandTest.php b/tests/CleanCommandTest.php index b5aa9ebc..4dd740f6 100644 --- a/tests/CleanCommandTest.php +++ b/tests/CleanCommandTest.php @@ -3,7 +3,6 @@ namespace Silber\Bouncer\Tests; use Illuminate\Console\Application as Artisan; -use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use Silber\Bouncer\Console\CleanCommand; use Silber\Bouncer\Database\Ability; diff --git a/tests/Concerns/TestsClipboards.php b/tests/Concerns/TestsClipboards.php index 69f2a93e..2752597e 100644 --- a/tests/Concerns/TestsClipboards.php +++ b/tests/Concerns/TestsClipboards.php @@ -2,14 +2,10 @@ namespace Silber\Bouncer\Tests\Concerns; -use PHPUnit\Framework\Attributes\Test; -use PHPUnit\Framework\Attributes\DataProvider; - +use Illuminate\Cache\NullStore; +use Silber\Bouncer\CachedClipboard; use Silber\Bouncer\Clipboard; use Workbench\App\Models\User; -use Silber\Bouncer\CachedClipboard; - -use Illuminate\Cache\NullStore; trait TestsClipboards { @@ -26,14 +22,14 @@ function ($authoriesCount = 1, $authority = User::class) { return static::provideBouncer( new Clipboard, $authoriesCount, $authority ); - } + }, ], 'null cached clipboard' => [ function ($authoriesCount = 1, $authority = User::class) { return static::provideBouncer( new CachedClipboard(new NullStore), $authoriesCount, $authority ); - } + }, ], ]; } diff --git a/tests/CustomAuthorityTest.php b/tests/CustomAuthorityTest.php index 263e1ca2..50c7647b 100644 --- a/tests/CustomAuthorityTest.php +++ b/tests/CustomAuthorityTest.php @@ -2,11 +2,8 @@ namespace Silber\Bouncer\Tests; -use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\DataProvider; - -use Silber\Bouncer\Database\HasRolesAndAbilities; -use Workbench\App\Models\User; +use PHPUnit\Framework\Attributes\Test; use Workbench\App\Models\Account; class CustomAuthorityTest extends BaseTestCase diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php index 09b7e6c5..4f98ecf3 100644 --- a/tests/FactoryTest.php +++ b/tests/FactoryTest.php @@ -2,14 +2,11 @@ namespace Silber\Bouncer\Tests; -use PHPUnit\Framework\Attributes\Test; -use PHPUnit\Framework\Attributes\DataProvider; - -use Silber\Bouncer\Bouncer; use Illuminate\Auth\Access\Gate; use Illuminate\Container\Container; +use PHPUnit\Framework\Attributes\Test; +use Silber\Bouncer\Bouncer; use Workbench\App\Models\User; -use Workbench\App\Models\Account; class FactoryTest extends BaseTestCase { diff --git a/tests/ForbidTest.php b/tests/ForbidTest.php index b0786e73..650459ff 100644 --- a/tests/ForbidTest.php +++ b/tests/ForbidTest.php @@ -2,13 +2,10 @@ namespace Silber\Bouncer\Tests; -use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\DataProvider; - -use Silber\Bouncer\Database\Role; -use Silber\Bouncer\Database\Ability; -use Workbench\App\Models\User; +use PHPUnit\Framework\Attributes\Test; use Workbench\App\Models\Account; +use Workbench\App\Models\User; class ForbidTest extends BaseTestCase { diff --git a/tests/HasRolesAndAbilitiesTraitTest.php b/tests/HasRolesAndAbilitiesTraitTest.php index 72193a5b..6c22844f 100644 --- a/tests/HasRolesAndAbilitiesTraitTest.php +++ b/tests/HasRolesAndAbilitiesTraitTest.php @@ -2,13 +2,11 @@ namespace Silber\Bouncer\Tests; -use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\DataProvider; - +use PHPUnit\Framework\Attributes\Test; use Silber\Bouncer\Database\Models; use Workbench\App\Models\User; use Workbench\App\Models\UserWithSoftDeletes; -use Workbench\App\Models\Account; class HasRolesAndAbilitiesTraitTest extends BaseTestCase { diff --git a/tests/MultiTenancyTest.php b/tests/MultiTenancyTest.php index cb09baec..b9890e9d 100644 --- a/tests/MultiTenancyTest.php +++ b/tests/MultiTenancyTest.php @@ -2,21 +2,14 @@ namespace Silber\Bouncer\Tests; -use PHPUnit\Framework\Attributes\Test; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; use PHPUnit\Framework\Attributes\DataProvider; - -use Silber\Bouncer\Database\Role; +use PHPUnit\Framework\Attributes\Test; +use Silber\Bouncer\Contracts\Scope as ScopeContract; use Silber\Bouncer\Database\Models; -use Silber\Bouncer\Database\Ability; use Silber\Bouncer\Database\Scope\Scope; -use Silber\Bouncer\Contracts\Scope as ScopeContract; - -use Illuminate\Events\Dispatcher; -use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\BelongsToMany; - use Workbench\App\Models\User; -use Workbench\App\Models\Account; class MultiTenancyTest extends BaseTestCase { @@ -24,10 +17,8 @@ class MultiTenancyTest extends BaseTestCase /** * Reset any scopes that have been applied in a test. - * - * @return void */ - function tearDown(): void + public function tearDown(): void { Models::scope(new Scope); @@ -338,8 +329,8 @@ public function role_abilities_can_be_excluded_from_scopes($provider) [$bouncer, $user] = $provider(); $bouncer->scope()->to(1) - ->onlyRelations() - ->dontScopeRoleAbilities(); + ->onlyRelations() + ->dontScopeRoleAbilities(); $bouncer->allow('admin')->to('delete', User::class); @@ -400,8 +391,6 @@ public function can_remove_the_scope_temporarily() } } - - class MultiTenancyNullScopeStub implements ScopeContract { public function to() diff --git a/tests/MultipleAbilitiesTest.php b/tests/MultipleAbilitiesTest.php index d5c35df1..1e1433ea 100644 --- a/tests/MultipleAbilitiesTest.php +++ b/tests/MultipleAbilitiesTest.php @@ -2,11 +2,10 @@ namespace Silber\Bouncer\Tests; -use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\DataProvider; - -use Workbench\App\Models\User; +use PHPUnit\Framework\Attributes\Test; use Workbench\App\Models\Account; +use Workbench\App\Models\User; class MultipleAbilitiesTest extends BaseTestCase { @@ -89,9 +88,9 @@ public function allowing_multiple_abilities_via_a_map($provider) $account2 = Account::create(); $bouncer->allow($user1)->to([ - 'edit' => User::class, + 'edit' => User::class, 'delete' => $user1, - 'view' => Account::class, + 'view' => Account::class, 'update' => $account1, 'access-dashboard', ]); @@ -159,14 +158,14 @@ public function disallowing_multiple_abilities_via_a_map($provider) $account2 = Account::create(); $bouncer->allow($user1)->to([ - 'edit' => User::class, + 'edit' => User::class, 'delete' => $user1, - 'view' => Account::class, + 'view' => Account::class, 'update' => $account1, ]); $bouncer->disallow($user1)->to([ - 'edit' => User::class, + 'edit' => User::class, 'update' => $account1, ]); @@ -242,14 +241,14 @@ public function forbidding_multiple_abilities_via_a_map($provider) $account2 = Account::create(); $bouncer->allow($user1)->to([ - 'edit' => User::class, + 'edit' => User::class, 'delete' => $user1, - 'view' => Account::class, + 'view' => Account::class, 'update' => $account1, ]); $bouncer->forbid($user1)->to([ - 'edit' => User::class, + 'edit' => User::class, 'update' => $account1, ]); @@ -314,21 +313,21 @@ public function unforbidding_multiple_abilities_via_a_map($provider) $account2 = Account::create(); $bouncer->allow($user1)->to([ - 'edit' => User::class, + 'edit' => User::class, 'delete' => $user1, - 'view' => Account::class, + 'view' => Account::class, 'update' => $account1, ]); $bouncer->forbid($user1)->to([ - 'edit' => User::class, + 'edit' => User::class, 'delete' => $user1, - 'view' => Account::class, + 'view' => Account::class, 'update' => $account1, ]); $bouncer->unforbid($user1)->to([ - 'edit' => User::class, + 'edit' => User::class, 'update' => $account1, ]); diff --git a/tests/OwnershipTest.php b/tests/OwnershipTest.php index efc2521a..2e056211 100644 --- a/tests/OwnershipTest.php +++ b/tests/OwnershipTest.php @@ -2,14 +2,9 @@ namespace Silber\Bouncer\Tests; -use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\DataProvider; - -use Silber\Bouncer\Database\Role; +use PHPUnit\Framework\Attributes\Test; use Silber\Bouncer\Database\Models; -use Silber\Bouncer\Database\Ability; - -use Workbench\App\Models\User; use Workbench\App\Models\Account; class OwnershipTest extends BaseTestCase @@ -187,7 +182,7 @@ public function can_use_custom_ownership_attribute_for_model_type($provider) Models::reset(); } - + #[Test] #[DataProvider('bouncerProvider')] public function can_forbid_abilities_after_owning_a_model_class($provider) diff --git a/tests/QueryScopes/RoleScopesTest.php b/tests/QueryScopes/RoleScopesTest.php index 19590026..9022d76a 100644 --- a/tests/QueryScopes/RoleScopesTest.php +++ b/tests/QueryScopes/RoleScopesTest.php @@ -3,11 +3,9 @@ namespace Silber\Bouncer\Tests\QueryScopes; use PHPUnit\Framework\Attributes\Test; -use PHPUnit\Framework\Attributes\DataProvider; - -use Workbench\App\Models\User; use Silber\Bouncer\Database\Role; use Silber\Bouncer\Tests\BaseTestCase; +use Workbench\App\Models\User; class RoleScopesTest extends BaseTestCase { diff --git a/tests/QueryScopes/UserIsScopesTest.php b/tests/QueryScopes/UserIsScopesTest.php index 3cfa95d0..8291b982 100644 --- a/tests/QueryScopes/UserIsScopesTest.php +++ b/tests/QueryScopes/UserIsScopesTest.php @@ -3,11 +3,8 @@ namespace Silber\Bouncer\Tests\QueryScopes; use PHPUnit\Framework\Attributes\Test; -use PHPUnit\Framework\Attributes\DataProvider; - -use Workbench\App\Models\User; -use Silber\Bouncer\Database\Role; use Silber\Bouncer\Tests\BaseTestCase; +use Workbench\App\Models\User; class UserIsScopesTest extends BaseTestCase { diff --git a/tests/ReportedIssuesTest.php b/tests/ReportedIssuesTest.php index 8cd90545..9efdcb87 100644 --- a/tests/ReportedIssuesTest.php +++ b/tests/ReportedIssuesTest.php @@ -2,14 +2,8 @@ namespace Silber\Bouncer\Tests; -use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\DataProvider; - -use Silber\Bouncer\Database\Role; -use Silber\Bouncer\Database\Ability; - -use Workbench\App\Models\User; -use Workbench\App\Models\Account; +use PHPUnit\Framework\Attributes\Test; class ReportedIssuesTest extends BaseTestCase { @@ -20,7 +14,7 @@ class ReportedIssuesTest extends BaseTestCase */ #[Test] #[DataProvider('bouncerProvider')] - function forbid_an_ability_on_everything_with_zero_id($provider) + public function forbid_an_ability_on_everything_with_zero_id($provider) { [$bouncer, $user1, $user2, $user3] = $provider(3); diff --git a/tests/SyncTest.php b/tests/SyncTest.php index 8c7ecb8c..2e8df6e8 100644 --- a/tests/SyncTest.php +++ b/tests/SyncTest.php @@ -2,14 +2,12 @@ namespace Silber\Bouncer\Tests; -use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\DataProvider; - -use Silber\Bouncer\Database\Role; +use PHPUnit\Framework\Attributes\Test; use Silber\Bouncer\Database\Ability; - -use Workbench\App\Models\User; +use Silber\Bouncer\Database\Role; use Workbench\App\Models\Account; +use Workbench\App\Models\User; class SyncTest extends BaseTestCase { @@ -21,9 +19,9 @@ public function syncing_roles($provider) { [$bouncer, $user] = $provider(); - $admin = $this->role('admin'); - $editor = $this->role('editor'); - $reviewer = $this->role('reviewer'); + $admin = $this->role('admin'); + $editor = $this->role('editor'); + $reviewer = $this->role('reviewer'); $subscriber = $this->role('subscriber'); $user->assign([$admin, $editor]); diff --git a/tests/TablePrefixTest.php b/tests/TablePrefixTest.php index fe0d21a8..d7b4f9f9 100644 --- a/tests/TablePrefixTest.php +++ b/tests/TablePrefixTest.php @@ -2,11 +2,8 @@ namespace Silber\Bouncer\Tests; -use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\DataProvider; - -use Workbench\App\Models\User; -use Workbench\App\Models\Account; +use PHPUnit\Framework\Attributes\Test; class TablePrefixTest extends BaseTestCase { diff --git a/tests/TitledAbilitiesTest.php b/tests/TitledAbilitiesTest.php index d1f2b737..0e77a1bc 100644 --- a/tests/TitledAbilitiesTest.php +++ b/tests/TitledAbilitiesTest.php @@ -3,12 +3,9 @@ namespace Silber\Bouncer\Tests; use PHPUnit\Framework\Attributes\Test; -use PHPUnit\Framework\Attributes\DataProvider; - use Silber\Bouncer\Database\Ability; - -use Workbench\App\Models\User; use Workbench\App\Models\Account; +use Workbench\App\Models\User; class TitledAbilitiesTest extends BaseTestCase { diff --git a/tests/Unit/Constraints/BuilderTest.php b/tests/Unit/Constraints/BuilderTest.php index 56f91802..7c8b68e0 100644 --- a/tests/Unit/Constraints/BuilderTest.php +++ b/tests/Unit/Constraints/BuilderTest.php @@ -3,12 +3,10 @@ namespace Silber\Bouncer\Tests\Unit\Constraints; use PHPUnit\Framework\Attributes\Test; -use PHPUnit\Framework\Attributes\DataProvider; - use PHPUnit\Framework\TestCase; -use Silber\Bouncer\Constraints\Group; use Silber\Bouncer\Constraints\Builder; use Silber\Bouncer\Constraints\Constraint; +use Silber\Bouncer\Constraints\Group; class BuilderTest extends TestCase { diff --git a/tests/Unit/Constraints/ConstraintTest.php b/tests/Unit/Constraints/ConstraintTest.php index b34d2132..2b1b7039 100644 --- a/tests/Unit/Constraints/ConstraintTest.php +++ b/tests/Unit/Constraints/ConstraintTest.php @@ -3,15 +3,12 @@ namespace Silber\Bouncer\Tests\Unit\Constraints; use PHPUnit\Framework\Attributes\Test; -use PHPUnit\Framework\Attributes\DataProvider; - -use Workbench\App\Models\User; -use Workbench\App\Models\Account; - use PHPUnit\Framework\TestCase; +use Silber\Bouncer\Constraints\ColumnConstraint; use Silber\Bouncer\Constraints\Constraint; use Silber\Bouncer\Constraints\ValueConstraint; -use Silber\Bouncer\Constraints\ColumnConstraint; +use Workbench\App\Models\Account; +use Workbench\App\Models\User; class ConstraintTest extends TestCase { diff --git a/tests/Unit/Constraints/GroupsTest.php b/tests/Unit/Constraints/GroupsTest.php index 4aa4f031..ebee2595 100644 --- a/tests/Unit/Constraints/GroupsTest.php +++ b/tests/Unit/Constraints/GroupsTest.php @@ -3,14 +3,11 @@ namespace Silber\Bouncer\Tests\Unit\Constraints; use PHPUnit\Framework\Attributes\Test; -use PHPUnit\Framework\Attributes\DataProvider; - -use Workbench\App\Models\User; -use Workbench\App\Models\Account; - use PHPUnit\Framework\TestCase; -use Silber\Bouncer\Constraints\Group; use Silber\Bouncer\Constraints\Constraint; +use Silber\Bouncer\Constraints\Group; +use Workbench\App\Models\Account; +use Workbench\App\Models\User; class GroupsTest extends TestCase { @@ -123,7 +120,6 @@ public function group_can_be_added_to() /** * Convert the given object to JSON, then back. * - * @param \Silber\Bouncer\Constraints\Group $group * @return \Silber\Bouncer\Constraints\Group */ protected function serializeAndDeserializeGroup(Group $group) diff --git a/tests/WildcardsTest.php b/tests/WildcardsTest.php index 93525bf5..bb0f19ab 100644 --- a/tests/WildcardsTest.php +++ b/tests/WildcardsTest.php @@ -2,14 +2,10 @@ namespace Silber\Bouncer\Tests; -use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\DataProvider; - -use Silber\Bouncer\Database\Role; -use Silber\Bouncer\Database\Ability; - -use Workbench\App\Models\User; +use PHPUnit\Framework\Attributes\Test; use Workbench\App\Models\Account; +use Workbench\App\Models\User; class WildcardsTest extends BaseTestCase { diff --git a/workbench/app/Models/Account.php b/workbench/app/Models/Account.php index 51c814a3..96e2b379 100644 --- a/workbench/app/Models/Account.php +++ b/workbench/app/Models/Account.php @@ -3,12 +3,12 @@ namespace Workbench\App\Models; use Illuminate\Database\Eloquent\Model; -use Silber\Bouncer\Database\HasRolesAndAbilities; use Silber\Bouncer\Database\Concerns\Authorizable; +use Silber\Bouncer\Database\HasRolesAndAbilities; class Account extends Model { use Authorizable, HasRolesAndAbilities; protected $guarded = []; -} \ No newline at end of file +} diff --git a/workbench/app/Models/User.php b/workbench/app/Models/User.php index cdfa55d3..4ce47a25 100644 --- a/workbench/app/Models/User.php +++ b/workbench/app/Models/User.php @@ -3,12 +3,12 @@ namespace Workbench\App\Models; use Illuminate\Database\Eloquent\Model; -use Silber\Bouncer\Database\HasRolesAndAbilities; use Silber\Bouncer\Database\Concerns\Authorizable; +use Silber\Bouncer\Database\HasRolesAndAbilities; class User extends Model { use Authorizable, HasRolesAndAbilities; protected $guarded = []; -} \ No newline at end of file +} diff --git a/workbench/app/Models/UserWithSoftDeletes.php b/workbench/app/Models/UserWithSoftDeletes.php index 4e908b56..8b7ecc01 100644 --- a/workbench/app/Models/UserWithSoftDeletes.php +++ b/workbench/app/Models/UserWithSoftDeletes.php @@ -9,4 +9,4 @@ class UserWithSoftDeletes extends User use SoftDeletes; public $table = 'users'; -} \ No newline at end of file +} diff --git a/workbench/database/migrations/create_bouncer_test_tables.php b/workbench/database/migrations/create_bouncer_test_tables.php index 6278be90..28215a16 100644 --- a/workbench/database/migrations/create_bouncer_test_tables.php +++ b/workbench/database/migrations/create_bouncer_test_tables.php @@ -1,8 +1,7 @@