Completed
Branch MagicUser (b8f336)
by Patrick
03:44
created

FlipsideAPIUser::__get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 9.6666
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
    public function getEmail()
66
    {
67
        if($this->userData === null)
68
        {
69
            return parent::getEmail();
70
        }
71
        return $this->userData->mail;
72
    }
73
74
    public function getUid()
75
    {
76
        if($this->userData === null)
77
        {
78
            return parent::getUid();
79
        }
80
        return $this->userData->uid;
81
    }
82
83
    public function getPhoneNumber()
84
    {
85
        if($this->userData === null)
86
        {
87
            return parent::getPhoneNumber();
88
        }
89
        return $this->userData->mobile;
90
    }
91
92
    public function getOrganization()
93
    {
94
        if($this->userData === null)
95
        {
96
            return parent::getOrganization();
97
        }
98
        return $this->userData->o;
99
    }
100
101
    public function getTitles()
102
    {
103
        if($this->userData === null)
104
        {
105
            return parent::getTitles();
106
        }
107
        return $this->userData->title;
108
    }
109
110
    public function getState()
111
    {
112
        if($this->userData === null)
113
        {
114
            return parent::getState();
115
        }
116
        return $this->userData->st;
117
    }
118
119
    public function getCity()
120
    {
121
        if($this->userData === null)
122
        {
123
            return parent::getCity();
124
        }
125
        return $this->userData->l;
126
    }
127
128
    public function getLastName()
129
    {
130
        if($this->userData === null)
131
        {
132
            return parent::getLastName();
133
        }
134
        return $this->userData->sn;
135
    }
136
137
    public function getNickName()
138
    {
139
        if($this->userData === null)
140
        {
141
            return parent::getNickName();
142
        }
143
        return $this->userData->displayname;
144
    }
145
146
    public function getAddress()
147
    {
148
        if($this->userData === null)
149
        {
150
            return parent::getAddress();
151
        }
152
        return $this->userData->postaladdress;
153
    }
154
155
    public function getPostalCode()
156
    {
157
        if($this->userData === null)
158
        {
159
            return parent::getPostalCode();
160
        }
161
        return $this->userData->postalcode;
162
    }
163
164
    public function getCountry()
165
    {
166
        if($this->userData === null)
167
        {
168
            return parent::getCountry();
169
        }
170
        return $this->userData->c;
171
    }
172
173
    public function getOrganizationUnits()
174
    {
175
        if($this->userData === null)
176
        {
177
            return parent::getOrganizationUnits();
178
        }
179
        return $this->userData->ou;
180
    }
181
182
    public function getLoginProviders()
183
    {
184
        if($this->userData === null)
185
        {
186
            return parent::getLoginProviders();
187
        }
188
        return $this->userData->host;
189
    }
190
}
191
192