Completed
Push — master ( e938ca...eb16f0 )
by Patrick
02:57
created

FlipsideAPIUser::__construct()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 5

Duplication

Lines 12
Ratio 80 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 5
c 1
b 0
f 0
nc 3
nop 1
dl 12
loc 15
rs 9.2
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 View Code Duplication
        if(($data !== false) && !isset($data['extended']))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

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