1 | <?php |
||
24 | class Permission |
||
25 | { |
||
26 | /** |
||
27 | * The Guard implementation. |
||
28 | * |
||
29 | * @var Guard |
||
30 | */ |
||
31 | protected $auth; |
||
32 | |||
33 | /** |
||
34 | * List of permissions that can be accessed by public users. |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | protected $publicAccess = [ |
||
39 | 'issue-view', |
||
40 | ]; |
||
41 | |||
42 | /** |
||
43 | * Create a new filter instance. |
||
44 | * |
||
45 | * @param Guard $auth |
||
46 | */ |
||
47 | 43 | public function __construct(Guard $auth) |
|
51 | |||
52 | /** |
||
53 | * Handle an incoming request. |
||
54 | * |
||
55 | * @param Request $request |
||
56 | * @param \Closure $next |
||
57 | * |
||
58 | * @return mixed |
||
59 | */ |
||
60 | 42 | public function handle(Request $request, Closure $next) |
|
61 | { |
||
62 | 42 | $permission = $this->getPermission($request); |
|
63 | 42 | $user = $this->auth->user(); |
|
64 | /** @var ProjectModel|null $project */ |
||
65 | 42 | $project = $request->route()->getParameter('project'); |
|
66 | |||
67 | // Check if user has the permission |
||
68 | // & if the user can access the current context (e.g. is one of the project users) |
||
69 | 42 | if (app('tinyissue.settings')->isPublicProjectsEnabled() |
|
|
|||
70 | 42 | && in_array($permission, $this->publicAccess) |
|
71 | 42 | && $project instanceof ProjectModel && !$project->isPrivate()) { |
|
72 | // Ignore we are ok to view issues in public project |
||
73 | 42 | } elseif (!$this->auth->guest() |
|
74 | 42 | && (!$user->permission($permission) || !$user->permissionInContext($request->route()->parameters()))) { |
|
75 | 8 | abort(401); |
|
76 | } |
||
77 | |||
78 | 38 | return $next($request); |
|
79 | } |
||
80 | |||
81 | /** |
||
82 | * Returns the permission defined in route action. |
||
83 | * |
||
84 | * @param Request $request |
||
85 | * |
||
86 | * @return mixed |
||
87 | */ |
||
88 | 42 | protected function getPermission(Request $request) |
|
94 | } |
||
95 |
This check looks for the bodies of
if
statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
if
bodies can be removed. If you have an empty if but statements in theelse
branch, consider inverting the condition.could be turned into
This is much more concise to read.