Skip to content

Commit 8444a48

Browse files
committed
Slightly modified to match PSR-12
1 parent ecc1193 commit 8444a48

File tree

10 files changed

+45
-66
lines changed

10 files changed

+45
-66
lines changed

src/Console/InstallCommand.php

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class InstallCommand extends Command
2323

2424
/**
2525
* Execute the console command.
26+
*
27+
* @return void
2628
*/
2729
public function handle(): void
2830
{

src/Contracts/AddsTeamMembers.php

-11
This file was deleted.

src/Contracts/DeletesTeams.php

-11
This file was deleted.

src/Contracts/RemovesTeamMembers.php

-11
This file was deleted.

src/Contracts/UpdatesTeamNames.php

-11
This file was deleted.

src/Middleware/Teams.php

+13
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ protected function authorization(Request $request, string $method, string|array
6363

6464
/**
6565
* Check user's ability for the team.
66+
*
67+
* @param Request $request
68+
* @param $team
69+
* @param string $ability
70+
* @param array|null $models
71+
* @return bool
6672
*/
6773
protected function checkTeamAbility(Request $request, $team, string $ability, ?array $models): bool
6874
{
@@ -86,8 +92,11 @@ protected function checkTeamAbility(Request $request, $team, string $ability, ?a
8692
return $request->user()->hasTeamAbility($team, $ability, $entity);
8793
}
8894

95+
8996
/**
9097
* The request is unauthorized, so it handles the aborting/redirecting.
98+
*
99+
* @return RedirectResponse
91100
*/
92101
protected function unauthorized(): RedirectResponse
93102
{
@@ -112,6 +121,10 @@ protected function unauthorized(): RedirectResponse
112121

113122
/**
114123
* Get the arguments parameters for the gate.
124+
*
125+
* @param Request $request
126+
* @param array|null $models
127+
* @return array
115128
*/
116129
protected function getGateArguments(Request $request, ?array $models): array
117130
{

src/Support/Facades/Teams.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @method static string model(string $model)
1010
* @method static object instance(string $model)
1111
*
12-
* @see \Jurager\Teams\Support\Services\TeamsService
12+
* @see TeamsService
1313
*/
1414
class Teams extends Facade
1515
{

src/Support/Services/TeamsService.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
namespace Jurager\Teams\Support\Services;
44

5+
use Illuminate\Database\Eloquent\Model;
56
use Illuminate\Support\Facades\Config;
7+
use RuntimeException;
8+
use Exception;
69

710
class TeamsService
811
{
@@ -23,7 +26,7 @@ public function __construct()
2326
*
2427
* @param string $model
2528
* @return object
26-
* @throws \Exception
29+
* @throws Exception
2730
*/
2831
public function instance(string $model): object
2932
{
@@ -35,7 +38,7 @@ public function instance(string $model): object
3538
*
3639
* @param string $model
3740
* @return string
38-
* @throws \Exception
41+
* @throws Exception
3942
*/
4043
public function model(string $model): string
4144
{
@@ -48,16 +51,16 @@ public function model(string $model): string
4851
* @param string $key
4952
* @param bool $instance
5053
* @return string|object
51-
* @throws \Exception
54+
* @throws Exception
5255
*
53-
* @template T of \Illuminate\Database\Eloquent\Model
56+
* @template T of Model
5457
*/
5558
private function getModel(string $key, bool $instance = false): string|object
5659
{
5760
$modelClass = $this->models[$key] ?? null;
5861

5962
if (!$modelClass || !class_exists($modelClass)) {
60-
throw new \RuntimeException("Model class for key $key not found.");
63+
throw new RuntimeException("Model class for key $key not found.");
6164
}
6265

6366
return $instance ? new $modelClass() : $modelClass;

src/Traits/HasMembers.php

+13-12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Jurager\Teams\Events\TeamMemberUpdated;
1616
use Jurager\Teams\Models\Owner;
1717
use Jurager\Teams\Support\Facades\Teams;
18+
use RuntimeException;
1819

1920
trait HasMembers
2021
{
@@ -113,17 +114,17 @@ public function hasUser(object $user): bool
113114
public function addUser(object $user, string $role_keyword): void
114115
{
115116
if ($user->id === $this->owner->id) {
116-
throw new \RuntimeException(__('Owner already belongs to the team.'));
117+
throw new RuntimeException(__('Owner already belongs to the team.'));
117118
}
118119

119120
if ($this->hasUser($user)) {
120-
throw new \RuntimeException(__('User already belongs to the team.'));
121+
throw new RuntimeException(__('User already belongs to the team.'));
121122
}
122123

123124
$role = $this->getRole($role_keyword);
124125

125126
if (!$role) {
126-
throw new \RuntimeException(__('Unable to find a role :role within team.', ['role' => $role_keyword]));
127+
throw new RuntimeException(__('Unable to find a role :role within team.', ['role' => $role_keyword]));
127128
}
128129

129130
// Dispatch an event before attaching the user
@@ -146,17 +147,17 @@ public function addUser(object $user, string $role_keyword): void
146147
public function updateUser(object $user, string $role_keyword): void
147148
{
148149
if ($user->id === $this->owner->id) {
149-
throw new \RuntimeException(__('You may not change the team owner.'));
150+
throw new RuntimeException(__('You may not change the team owner.'));
150151
}
151152

152153
if (!$this->hasUser($user)) {
153-
throw new \RuntimeException(__('User not belongs to the team.'));
154+
throw new RuntimeException(__('User not belongs to the team.'));
154155
}
155156

156157
$role = $this->getRole($role_keyword);
157158

158159
if (!$role) {
159-
throw new \RuntimeException(__('Unable to find a role :role within team.', ['role' => $role_keyword]));
160+
throw new RuntimeException(__('Unable to find a role :role within team.', ['role' => $role_keyword]));
160161
}
161162

162163
// Update the user role for the team
@@ -176,11 +177,11 @@ public function updateUser(object $user, string $role_keyword): void
176177
public function deleteUser(object $user): void
177178
{
178179
if ($user->id === $this->owner->id) {
179-
throw new \RuntimeException(__('You may not remove the team owner.'));
180+
throw new RuntimeException(__('You may not remove the team owner.'));
180181
}
181182

182183
if (!$this->hasUser($user)) {
183-
throw new \RuntimeException(__('User not belongs to the team.'));
184+
throw new RuntimeException(__('User not belongs to the team.'));
184185
}
185186

186187
// Detach the user from the team
@@ -228,7 +229,7 @@ public function userHasPermission(object $user, string|array $permissions, bool
228229
/**
229230
* Check if the team has a specific role by ID or code or any roles at all
230231
*
231-
* @param string|null $keyword The role ID or code to check for. If null, checks for any roles.
232+
* @param int|string|null $keyword The role ID or code to check for. If null, checks for any roles.
232233
* @return bool
233234
*/
234235
public function hasRole(int|string|null $keyword = null): bool
@@ -263,7 +264,7 @@ public function getRole(int|string $keyword): object|null
263264
public function addRole(string $code, array $permissions, string|null $name = null, string|null $description = null): object
264265
{
265266
if ($this->hasRole($code)) {
266-
throw new \RuntimeException("Role with code '$code' already exists.");
267+
throw new RuntimeException("Role with code '$code' already exists.");
267268
}
268269

269270
$role = $this->roles()->create([
@@ -325,7 +326,7 @@ public function deleteRole(int|string $keyword): bool
325326
/**
326327
* Check if the team has a specific group by ID or code or any groups at all
327328
*
328-
* @param string|null $keyword The role ID or code to check for. If null, checks for any groups.
329+
* @param int|string|null $keyword The role ID or code to check for. If null, checks for any groups.
329330
* @return bool
330331
*/
331332
public function hasGroup(int|string|null $keyword = null): bool
@@ -359,7 +360,7 @@ public function getGroup(int|string $keyword): object|null
359360
public function addGroup(string $code, array $permissions = [], string|null $name = null): object
360361
{
361362
if ($this->hasGroup($code)) {
362-
throw new \RuntimeException("Group with code '$code' already exists.");
363+
throw new RuntimeException("Group with code '$code' already exists.");
363364
}
364365

365366
$group = $this->groups()->create([

src/Traits/HasTeams.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ public function teamPermissions(object $team, string|null $scope = null): array
168168
/**
169169
* Determine if the user has the given permission on the given team.
170170
*
171+
* $require = true (all permissions in the array are required)
172+
* $require = false (only one or more permission in the array are required or $permissions is empty)
173+
*
171174
* @param object $team
172175
* @param string|array $permissions
173176
* @param bool $require
@@ -176,9 +179,6 @@ public function teamPermissions(object $team, string|null $scope = null): array
176179
*/
177180
public function hasTeamPermission(object $team, string|array $permissions, bool $require = false, string|null $scope = null): bool
178181
{
179-
//$require = true (all permissions in the array are required)
180-
//$require = false (only one or more permission in the array are required or $permissions is empty)
181-
182182
if ($this->ownsTeam($team)) {
183183
return true;
184184
}
@@ -238,7 +238,7 @@ public function teamAbilities(object $team, object $entity, bool $forbidden = fa
238238
*
239239
* This function is to verify permissions within a universal group.
240240
* Especially in cases where a team requires a group enabling user additions
241-
* and removals without direct affiliation with the team
241+
* and removals without direct affiliation with the team.
242242
*
243243
* Example: Each team should have a global group of moderators.
244244
*
@@ -438,6 +438,10 @@ private function getRelationName(object|string $classname): string
438438

439439
/**
440440
* Check for wildcard permissions.
441+
*
442+
* @param array $userPermissions
443+
* @param string $permission
444+
* @return bool
441445
*/
442446
private function checkPermissionWildcard(array $userPermissions, string $permission): bool
443447
{

0 commit comments

Comments
 (0)