Completed
Branch MagicUser (0f8166)
by Patrick
03:40
created

FlipsideAPIUser   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 57
rs 10
wmc 12
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 4
B isInGroupNamed() 0 21 5
A __get() 0 9 2
A __set() 0 3 1
1
<?php
2
namespace Auth;
3
if(!class_exists('Httpful\Request'))
4
{
5
    require(realpath(dirname(__FILE__)).'/../libs/httpful/bootstrap.php');
6
}
7
8
class FlipsideAPIUser extends User
9
{
10
    private $userData;
11
    private $groupData = null;
12
13
    public function __construct($data = false)
14
    {
15
        if(($data !== false) && !isset($data['extended']))
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
16
        {
17
            //Generic user object
18
            //TODO get from API
19
        }
20
        else
21
        {
22
            if(isset($data['extended']))
23
            {
24
                $this->userData = $data['extended'];
25
            }
26
        }
27
    }
28
29
    public function isInGroupNamed($name)
30
    {
31
        if($this->groupData === null)
32
        {
33
            $resp = \Httpful\Request::get('https://profiles.test.burningflipside.com/api/v1/users/me/groups')->authenticateWith($this->userData->uid, $this->userData->userPassword)->send();
34
            if($resp->hasErrors())
35
            {
36
                return false;
37
            }
38
            $this->groupData = $resp->body;
39
        }
40
        $count = count($this->groupData);
41
        for($i = 0; $i < $count; $i++)
42
        {
43
            if($this->groupData[$i]->cn === $name)
44
            {
45
                return true;
46
            }
47
        }
48
        return false;
49
    }
50
51
    public function __get($propName)
52
    {
53
        if($this->userData === null)
54
        {
55
            return parent::__get($propName);
56
        }
57
        $propName = strtolower($propName);
58
        return $this->userData->{$propName};
59
    }
60
61
    public function __set($propName, $value)
62
    {
63
    }
64
}
65
66