AuthorizedActions::authorizedActions()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 17
ccs 9
cts 9
cp 1
crap 4
rs 10
1
<?php
2
3
namespace Devpri\Tinre\Traits;
4
5
use Illuminate\Support\Facades\Auth;
6
7
trait AuthorizedActions
8
{
9 23
    public function authorizedActions(): array
10
    {
11 23
        $authorizedActions = [];
12
13 23
        $user = Auth::user();
14
15 23
        if (! $user) {
16 1
            return $authorizedActions;
17
        }
18
19 22
        foreach ($this->actions as $action) {
20 22
            if ($user->can($action, $this)) {
21 22
                $authorizedActions[] = $action;
22
            }
23
        }
24
25 22
        return $authorizedActions;
26
    }
27
}
28