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

SuperAdminRule::userProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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