BurningFlipside /
CommonCode
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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
|
|||
| 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 |
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.