Completed
Push — master ( 76b9d6...f2a606 )
by Terzi
04:33
created

SuperAdminRule   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 23
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 13 4
A userProvider() 0 3 1
1
<?php
2
3
namespace Terranet\Administrator\Auth;
4
5
use Illuminate\Contracts\Auth\Authenticatable;
6
7
class SuperAdminRule
8
{
9 3
    public function validate(Authenticatable $user = null)
10
    {
11 3
        $user = $user ?: $this->userProvider();
12
13 3
        if (!$user) {
14 1
            return false;
15
        }
16
17 2
        if (method_exists($user, 'isSuperAdmin')) {
18 1
            return \call_user_func([$user, 'isSuperAdmin']);
19
        }
20
21 1
        return 1 === (int) $user->getAuthIdentifier();
22
    }
23
24
    /**
25
     * @return null|Authenticatable
26
     */
27 1
    protected function userProvider()
28
    {
29 1
        return auth('admin')->user();
30
    }
31
}
32