Skip to content

Commit ecc1193

Browse files
committed
Slightly modified to match PSR-12
1 parent 5075b6d commit ecc1193

30 files changed

+58
-68
lines changed

config/teams.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,4 @@
8686
'middleware' => 'web'
8787
]
8888
],
89-
];
89+
];

database/migrations/create_abilities_table.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
use Illuminate\Support\Facades\Config;
66
use Illuminate\Support\Facades\Schema;
77

8-
return new class extends Migration
9-
{
8+
return new class () extends Migration {
109
/**
1110
* Run the migrations.
1211
*/

database/migrations/create_entity_ability_table.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Schema;
66

7-
return new class extends Migration
8-
{
7+
return new class () extends Migration {
98
/**
109
* Run the migrations.
1110
*/

database/migrations/create_entity_permission_table.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Schema;
66

7-
return new class extends Migration
8-
{
7+
return new class () extends Migration {
98
/**
109
* Run the migrations.
1110
*/

database/migrations/create_group_user_table.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Schema;
66

7-
return new class extends Migration
8-
{
7+
return new class () extends Migration {
98
/**
109
* Run the migrations.
1110
*/

database/migrations/create_groups_table.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
use Illuminate\Support\Facades\Config;
66
use Illuminate\Support\Facades\Schema;
77

8-
return new class extends Migration
9-
{
8+
return new class () extends Migration {
109
/**
1110
* Run the migrations.
1211
*/

database/migrations/create_invitations_table.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
use Illuminate\Support\Facades\Config;
66
use Illuminate\Support\Facades\Schema;
77

8-
return new class extends Migration
9-
{
8+
return new class () extends Migration {
109
/**
1110
* Run the migrations.
1211
*/

database/migrations/create_permissions_table.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
use Illuminate\Support\Facades\Config;
66
use Illuminate\Support\Facades\Schema;
77

8-
return new class extends Migration
9-
{
8+
return new class () extends Migration {
109
/**
1110
* Run the migrations.
1211
*/

database/migrations/create_roles_table.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
use Illuminate\Support\Facades\Config;
66
use Illuminate\Support\Facades\Schema;
77

8-
return new class extends Migration
9-
{
8+
return new class () extends Migration {
109
/**
1110
* Run the migrations.
1211
*/

database/migrations/create_team_user_table.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
use Illuminate\Support\Facades\Config;
66
use Illuminate\Support\Facades\Schema;
77

8-
return new class extends Migration
9-
{
8+
return new class () extends Migration {
109
/**
1110
* Run the migrations.
1211
*/
@@ -30,4 +29,4 @@ public function down(): void
3029
{
3130
Schema::dropIfExists('team_user');
3231
}
33-
};
32+
};

database/migrations/create_teams_table.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Schema;
66

7-
return new class extends Migration
8-
{
7+
return new class () extends Migration {
98
/**
109
* Run the migrations.
1110
*/

routes/web.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
Route::middleware(Config::get('teams.invitations.routes.middleware'))
88
->get(Config::get('teams.invitations.routes.url'), [InviteController::class, 'inviteAccept'])
9-
->name('teams.invitations.accept');
9+
->name('teams.invitations.accept');

src/Console/InstallCommand.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ public function handle(): void
3636
$this->call('vendor:publish', ['--tag' => 'teams-views', '--force' => true]);
3737

3838
// Directories...
39-
(new Filesystem)->ensureDirectoryExists(app_path('Actions/Teams'));
40-
(new Filesystem)->ensureDirectoryExists(app_path('Events'));
41-
(new Filesystem)->ensureDirectoryExists(app_path('Policies'));
39+
(new Filesystem())->ensureDirectoryExists(app_path('Actions/Teams'));
40+
(new Filesystem())->ensureDirectoryExists(app_path('Events'));
41+
(new Filesystem())->ensureDirectoryExists(app_path('Policies'));
4242

4343
// Actions...
44-
(new Filesystem)->copyDirectory(__DIR__.'/../../stubs/app/Actions/Teams', app_path('Actions/Teams/'));
44+
(new Filesystem())->copyDirectory(__DIR__.'/../../stubs/app/Actions/Teams', app_path('Actions/Teams/'));
4545

4646
// Policies...
47-
(new Filesystem)->copyDirectory(__DIR__.'/../../stubs/app/Policies', app_path('Policies'));
47+
(new Filesystem())->copyDirectory(__DIR__.'/../../stubs/app/Policies', app_path('Policies'));
4848

4949
// Controllers...
50-
(new Filesystem)->copyDirectory(__DIR__.'/../../stubs/app/Controllers', app_path('Http/Controllers/'));
50+
(new Filesystem())->copyDirectory(__DIR__.'/../../stubs/app/Controllers', app_path('Http/Controllers/'));
5151

5252
$this->info('All done. Have a nice journey.');
5353
}
54-
}
54+
}

src/Events/TeamEvent.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
abstract class TeamEvent
1010
{
11-
use Dispatchable, InteractsWithSockets, SerializesModels;
11+
use Dispatchable;
12+
use InteractsWithSockets;
13+
use SerializesModels;
1214

1315
/**
1416
* The team instance.

src/Mail/Invitation.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
class Invitation extends Mailable
1212
{
13-
use Queueable, SerializesModels;
13+
use Queueable;
14+
use SerializesModels;
1415

1516
/**
1617
* The team invitation instance.
@@ -38,4 +39,4 @@ public function build(): static
3839
'invitation' => $this->invitation,
3940
])])->subject(__('Team Invitation'));
4041
}
41-
}
42+
}

src/Middleware/Ability.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
class Ability extends Teams
99
{
10-
1110
/**
1211
* Handle incoming request.
1312
*
@@ -25,4 +24,4 @@ public function handle(Request $request, Closure $next, string $ability, ...$mod
2524

2625
return $next($request);
2726
}
28-
}
27+
}

src/Middleware/Permission.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
class Permission extends Teams
99
{
10-
1110
/**
1211
* Handle incoming request.
1312
*
@@ -26,4 +25,4 @@ public function handle(Request $request, Closure $next, string|array $permission
2625

2726
return $next($request);
2827
}
29-
}
28+
}

src/Middleware/Teams.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
class Teams
1414
{
15-
1615
/**
1716
* Check if the request has authorization to continue.
1817
*
@@ -122,7 +121,7 @@ protected function getGateArguments(Request $request, ?array $models): array
122121
}
123122

124123
// Filter out invalid model instances and fetch actual model instances
125-
return array_map(fn($model) => $model instanceof Model ? $model : $this->getModel($request, $model), $models);
124+
return array_map(fn ($model) => $model instanceof Model ? $model : $this->getModel($request, $model), $models);
126125
}
127126

128127
/**
@@ -145,4 +144,4 @@ protected function getModel(Request $request, string $model): string
145144
// Otherwise, retrieve the model from the request route, falling back to the original model name
146145
return $request->route($trimmedModel) ?: $trimmedModel;
147146
}
148-
}
147+
}

src/Models/Ability.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ public function roles(): MorphToMany
6363
->withPivot('forbidden')
6464
->withTimestamps();
6565
}
66-
}
66+
}

src/Models/Group.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function attachUser(Collection|Model $user): bool
103103
$users = $user instanceof Collection ? $user : collect([$user]);
104104

105105
// Filter only those users who are in the team
106-
$filteredUserIds = $users->filter(fn($item) => $this->team->hasUser($item));
106+
$filteredUserIds = $users->filter(fn ($item) => $this->team->hasUser($item));
107107

108108
// If there are users left after filtering, synchronize and return the result
109109
return $filteredUserIds->isNotEmpty() && $this->users()->syncWithoutDetaching($filteredUserIds->pluck('id')) > 0;
@@ -118,9 +118,9 @@ public function detachUser(Collection|Model $user): bool
118118
$users = $user instanceof Collection ? $user : collect([$user]);
119119

120120
// Filter only those users who are in the team
121-
$filteredUserIds = $users->filter(fn($item) => $this->team->hasUser($item));
121+
$filteredUserIds = $users->filter(fn ($item) => $this->team->hasUser($item));
122122

123123
// If there are any users left after filtering, we execute detach and return the result
124124
return $filteredUserIds ->isNotEmpty() && $this->users()->detach($filteredUserIds->pluck('id')) > 0;
125125
}
126-
}
126+
}

src/Models/Invitation.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ public function accept()
3939
// @todo: accept invitation
4040
// $this->team()->users()->attach($user, ['role' => $role]);
4141
// $invite->delete();
42-
}
43-
}
42+
}
43+
}

src/Models/Permission.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ public function roles(): MorphToMany
4444
{
4545
return $this->morphedByMany(Teams::model('role'), 'entity', 'entity_permission');
4646
}
47-
}
47+
}

src/Models/Team.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ public function __construct(array $attributes = [])
3434
parent::__construct($attributes);
3535
$this->table = Config::get('teams.tables.teams', 'teams');
3636
}
37-
}
37+
}

src/Support/Facades/Teams.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ protected static function getFacadeAccessor(): string
2222
{
2323
return TeamsService::class;
2424
}
25-
}
25+
}

src/Support/Services/TeamsService.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ private function getModel(string $key, bool $instance = false): string|object
6060
throw new \RuntimeException("Model class for key $key not found.");
6161
}
6262

63-
return $instance ? new $modelClass : $modelClass;
63+
return $instance ? new $modelClass() : $modelClass;
6464
}
65-
}
65+
}

src/TeamsServiceProvider.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function boot(): void
3939
$this->registerFacades();
4040
$this->registerMiddlewares();
4141

42-
if(Config::get('teams.invitations.enabled') && Config::get('teams.invitations.routes.register')) {
42+
if (Config::get('teams.invitations.enabled') && Config::get('teams.invitations.routes.register')) {
4343
$this->registerRoutes();
4444
}
4545
}
@@ -65,7 +65,7 @@ protected function configurePublishing(): void
6565
__DIR__ . '/../database/migrations/create_entity_permission_table.php' => database_path('migrations/2019_12_14_000010_create_entity_permission_table.php'),
6666
];
6767

68-
if(Config::get('teams.invitations.enabled')) {
68+
if (Config::get('teams.invitations.enabled')) {
6969
$migrations[__DIR__ . '/../database/migrations/create_invitations_table.php'] = database_path('migrations/2019_12_14_000012_create_invitations_table.php');
7070
}
7171

@@ -100,7 +100,7 @@ protected function configureCommands(): void
100100
protected function registerFacades(): void
101101
{
102102
$this->app->singleton('teams', static function () {
103-
return new TeamsService;
103+
return new TeamsService();
104104
});
105105
}
106106

src/Traits/HasMembers.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function users(): BelongsToMany
4848
*/
4949
public function abilities(): HasMany
5050
{
51-
return $this->hasMany(Teams::model('ability'), Config::get('teams.foreign_keys.team_id', 'team_id'),'id');
51+
return $this->hasMany(Teams::model('ability'), Config::get('teams.foreign_keys.team_id', 'team_id'), 'id');
5252
}
5353

5454
/**
@@ -58,7 +58,7 @@ public function abilities(): HasMany
5858
*/
5959
public function roles(): HasMany
6060
{
61-
return $this->hasMany(Teams::model('role'), Config::get('teams.foreign_keys.team_id', 'team_id'),'id');
61+
return $this->hasMany(Teams::model('role'), Config::get('teams.foreign_keys.team_id', 'team_id'), 'id');
6262
}
6363

6464
/**
@@ -68,7 +68,7 @@ public function roles(): HasMany
6868
*/
6969
public function groups(): HasMany
7070
{
71-
return $this->hasMany(Teams::model('group'), Config::get('teams.foreign_keys.team_id', 'team_id'),'id');
71+
return $this->hasMany(Teams::model('group'), Config::get('teams.foreign_keys.team_id', 'team_id'), 'id');
7272
}
7373

7474
/**
@@ -78,7 +78,7 @@ public function groups(): HasMany
7878
*/
7979
public function invitations(): HasMany
8080
{
81-
return $this->hasMany(Teams::model('invitation'), Config::get('teams.foreign_keys.team_id', 'team_id'),'id');
81+
return $this->hasMany(Teams::model('invitation'), Config::get('teams.foreign_keys.team_id', 'team_id'), 'id');
8282
}
8383

8484
/**
@@ -198,7 +198,7 @@ public function deleteUser(object $user): void
198198
*/
199199
public function hasUserWithEmail(string $email): bool
200200
{
201-
return $this->allUsers()->contains(fn($user) => $user->email === $email);
201+
return $this->allUsers()->contains(fn ($user) => $user->email === $email);
202202
}
203203

204204
/**
@@ -209,7 +209,7 @@ public function hasUserWithEmail(string $email): bool
209209
*/
210210
public function userRole(object $user): object|null
211211
{
212-
return $this->owner === $user ? new Owner : $this->getRole($this->users->firstWhere('id', $user->id)->membership->role->id ?? null);
212+
return $this->owner === $user ? new Owner() : $this->getRole($this->users->firstWhere('id', $user->id)->membership->role->id ?? null);
213213
}
214214

215215
/**
@@ -447,7 +447,7 @@ public function getPermissionIds(array $codes): array
447447

448448
if (!empty($newPermissions)) {
449449

450-
$items = array_map(fn($code) => [$teamIdField => $this->id ,'code' => $code], $newPermissions);
450+
$items = array_map(fn ($code) => [$teamIdField => $this->id ,'code' => $code], $newPermissions);
451451

452452
Teams::model('permission')::query()->insert($items);
453453

0 commit comments

Comments
 (0)