Completed
Push — master ( 26ea5b...d16af1 )
by Patrick
01:54
created

ProfilesAdminAPI   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateIsAdmin() 0 17 4
1
<?php
2
class ProfilesAdminAPI extends Http\Rest\RestAPI
3
{
4
    protected $user;
5
6
    public function validateIsAdmin($request, $nonFatal = false)
7
    {
8
        $this->user = $request->getAttribute('user');
9
        if($this->user === false)
10
        {
11
            throw new Exception('Must be logged in', \Http\Rest\ACCESS_DENIED);
12
        }
13
        if(!$this->user->isInGroupNamed('LDAPAdmins'))
14
        {
15
            if($nonFatal)
16
            {
17
                return false;
18
            }
19
            throw new Exception('Must be Admin', \Http\Rest\ACCESS_DENIED);
20
        }
21
        return true;
22
    }
23
}
24