Helper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 2
Metric Value
wmc 4
eloc 6
c 3
b 1
f 2
dl 0
loc 17
ccs 8
cts 8
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A authorizer() 0 3 1
A authenticated() 0 4 2
A except() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author enea dhack <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Enea\Authorization\Support;
13
14
use Enea\Authorization\Authorizer;
15
use Enea\Authorization\Contracts\Authorizable;
16
use Enea\Authorization\Contracts\Grantable;
17
use Illuminate\Support\Collection;
18
19
class Helper
20
{
21 19
    public function authenticated(?string $guard = null): ?Authorizable
22
    {
23 19
        $authenticated = auth($guard)->user();
24 19
        return $authenticated instanceof Authorizable ? $authenticated : null;
25
    }
26
27 1
    public function authorizer(): Authorizer
28
    {
29 1
        return app()->make(Authorizer::class);
30
    }
31
32 42
    public function except(Collection $grantableCollection, array $exceptNames): Collection
33
    {
34 42
        return $grantableCollection->filter(function (Grantable $grantable) use ($exceptNames): bool {
35 39
            return ! in_array($grantable, $exceptNames);
36 42
        });
37
    }
38
}
39