Skip to content

Commit

Permalink
Laravel Pint
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephSilber committed Mar 14, 2024
1 parent 52b979f commit 6b05279
Show file tree
Hide file tree
Showing 81 changed files with 329 additions and 642 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 1 addition & 5 deletions middleware/ScopeBouncer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

namespace App\Http\Middleware;

use Silber\Bouncer\Bouncer;

use Closure;
use Silber\Bouncer\Bouncer;

class ScopeBouncer
{
Expand All @@ -17,8 +16,6 @@ class ScopeBouncer

/**
* Constructor.
*
* @param \Silber\Bouncer\Bouncer $bouncer
*/
public function __construct(Bouncer $bouncer)
{
Expand All @@ -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)
Expand Down
15 changes: 7 additions & 8 deletions migrations/create_bouncer_tables.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php

use Silber\Bouncer\Database\Models;

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Silber\Bouncer\Database\Models;

return new class extends Migration
{
Expand Down Expand Up @@ -55,8 +54,8 @@ public function up()
);

$table->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) {
Expand All @@ -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');
});
}

Expand Down
15 changes: 3 additions & 12 deletions src/BaseClipboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()];
Expand All @@ -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)
Expand All @@ -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
*/
Expand All @@ -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)
Expand Down
28 changes: 8 additions & 20 deletions src/Bouncer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -31,8 +29,6 @@ class Bouncer

/**
* Constructor.
*
* @param \Silber\Bouncer\Guard $guard
*/
public function __construct(Guard $guard)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();

Expand All @@ -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);
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -406,6 +397,7 @@ public function cannot($ability, $arguments = [])
* Alias for the "can" method.
*
* @deprecated
*
* @param string $ability
* @param array|mixed $arguments
* @return bool
Expand All @@ -421,6 +413,7 @@ public function allows($ability, $arguments = [])
* Alias for the "cannot" method.
*
* @deprecated
*
* @param string $ability
* @param array|mixed $arguments
* @return bool
Expand All @@ -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 = [])
Expand All @@ -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 = [])
Expand Down Expand Up @@ -521,7 +512,6 @@ public function useUserModel($model)
/**
* Set custom table names.
*
* @param array $map
* @return $this
*/
public function tables(array $map)
Expand All @@ -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);
}
Expand All @@ -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 = [])
Expand Down
10 changes: 4 additions & 6 deletions src/BouncerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Loading

0 comments on commit 6b05279

Please sign in to comment.