Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
StyleCIBot committed Nov 22, 2024
1 parent 5be3af3 commit db4334c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class() extends Migration {
/**
* Run the migrations.
*
Expand Down
3 changes: 1 addition & 2 deletions src/Traits/RolesAndPermissionsHelpersTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ public function getSortedPermissonsWithRolesAndUsers($sortedRolesWithUsers, $per
/**
* Removes an users and permissions from role.
*
* @param Role$role The role
* @param Role $role The role
*
* @return void
*/
Expand Down Expand Up @@ -761,7 +761,6 @@ public function removeUsersAndRolesFromPermissions($permission)

foreach ($sortedPermissionsRolesUsers as $sortedPermissionsRolesUsersKey => $sortedPermissionsRolesUsersItem) {
if ($sortedPermissionsRolesUsersItem['permission']->id === $permission->id) {

// Remove Permission from roles
foreach ($sortedPermissionsRolesUsersItem['roles'] as $permissionRoleKey => $permissionRoleItem) {
$permissionRoleItem->detachPermission($permission);
Expand Down
1 change: 0 additions & 1 deletion src/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
'namespace' => 'jeremykenedy\LaravelRoles\App\Http\Controllers',
'prefix' => config('roles.GUIRoutesPrefix'),
], function () {

// Dashboards and CRUD Routes
Route::resource('roles', 'LaravelRolesController');
Route::resource('permissions', 'LaravelPermissionsController');
Expand Down
14 changes: 7 additions & 7 deletions tests/Feature/NPlusOneQueriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function setUp(): void
$this->assertEquals($this->rolesCount, config('roles.models.role')::count());
$this->assertEquals($this->permissionsCount, config('roles.models.permission')::count());

DB::listen(function(QueryExecuted $query) {
DB::listen(function (QueryExecuted $query) {
$this->queries++;
});
}
Expand All @@ -43,7 +43,7 @@ public function canPreloadRolesOnCollection(): void
$roleIds = config('roles.models.role')::pluck('id');

User::factory($this->usersCount)->create()
->each(function(User $user) use ($roleIds) {
->each(function (User $user) use ($roleIds) {
$user->roles()->attach($roleIds);
});
$this->assertEquals($this->usersCount, User::count() - $this->usersCountCorrection);
Expand All @@ -54,7 +54,7 @@ public function canPreloadRolesOnCollection(): void
$users = User::get();
$this->assertQueries(1);

$users->each(function(User $user) {
$users->each(function (User $user) {
$user->getRoles();
});
$this->queries = $this->queries - $this->usersCountCorrection;
Expand All @@ -64,7 +64,7 @@ public function canPreloadRolesOnCollection(): void
$users = User::with('roles')->get();
$this->assertQueries(2);

$users->each(function(User $user) {
$users->each(function (User $user) {
$user->getRoles();
});
$this->assertQueries(0);
Expand Down Expand Up @@ -142,7 +142,7 @@ public function canPreloadPermissionsOnCollection(): void
$roleIds = config('roles.models.role')::pluck('id');

User::factory($this->usersCount)->create()
->each(function(User $user) use ($roleIds) {
->each(function (User $user) use ($roleIds) {
$user->roles()->attach($roleIds);
});
$this->assertEquals($this->usersCount, User::count() - $this->usersCountCorrection);
Expand All @@ -153,7 +153,7 @@ public function canPreloadPermissionsOnCollection(): void
$users = User::get();
$this->assertQueries(1);

$users->each(function(User $user) {
$users->each(function (User $user) {
$user->getPermissions();
});
// rolePermissions(+getRoles) + userPermissions
Expand All @@ -164,7 +164,7 @@ public function canPreloadPermissionsOnCollection(): void
$users = User::with('roles', 'userPermissions')->get();
$this->assertQueries(3);

$users->each(function(User $user) {
$users->each(function (User $user) {
$user->getPermissions();
});
// TODO: optimize via relations: userPermissions and rolePermissions
Expand Down

0 comments on commit db4334c

Please sign in to comment.