| Total Complexity | 46 |
| Total Lines | 473 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like StandardClaims often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use StandardClaims, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | class StandardClaims implements \ArrayAccess |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | protected $sub; |
||
| 18 | /** |
||
| 19 | * @var null|string |
||
| 20 | */ |
||
| 21 | protected $name; |
||
| 22 | /** |
||
| 23 | * @var null|string |
||
| 24 | */ |
||
| 25 | protected $givenName; |
||
| 26 | /** |
||
| 27 | * @var null|string |
||
| 28 | */ |
||
| 29 | protected $familyName; |
||
| 30 | /** |
||
| 31 | * @var null|string |
||
| 32 | */ |
||
| 33 | protected $middleName; |
||
| 34 | /** |
||
| 35 | * @var null|string |
||
| 36 | */ |
||
| 37 | protected $nickname; |
||
| 38 | /** |
||
| 39 | * @var null|string |
||
| 40 | */ |
||
| 41 | protected $preferredUsername; |
||
| 42 | /** |
||
| 43 | * @var null|string |
||
| 44 | */ |
||
| 45 | protected $profile; |
||
| 46 | /** |
||
| 47 | * @var null|string |
||
| 48 | */ |
||
| 49 | protected $picture; |
||
| 50 | /** |
||
| 51 | * @var null|string |
||
| 52 | */ |
||
| 53 | protected $website; |
||
| 54 | /** |
||
| 55 | * @var null|string |
||
| 56 | */ |
||
| 57 | protected $email; |
||
| 58 | /** |
||
| 59 | * @var null|bool |
||
| 60 | */ |
||
| 61 | protected $emailVerified; |
||
| 62 | /** |
||
| 63 | * @var null|string |
||
| 64 | */ |
||
| 65 | protected $gender; |
||
| 66 | /** |
||
| 67 | * @var null|string |
||
| 68 | */ |
||
| 69 | protected $birthdate; |
||
| 70 | /** |
||
| 71 | * @var null|string |
||
| 72 | */ |
||
| 73 | protected $zoneinfo; |
||
| 74 | /** |
||
| 75 | * @var null|string |
||
| 76 | */ |
||
| 77 | protected $locale; |
||
| 78 | /** |
||
| 79 | * @var null|string |
||
| 80 | */ |
||
| 81 | protected $phoneNumber; |
||
| 82 | /** |
||
| 83 | * @var null|bool |
||
| 84 | */ |
||
| 85 | protected $phoneNumberVerified; |
||
| 86 | /** |
||
| 87 | * @var null|AddressClaim |
||
| 88 | */ |
||
| 89 | protected $address; |
||
| 90 | /** |
||
| 91 | * @var null|string |
||
| 92 | */ |
||
| 93 | protected $updatedAt; |
||
| 94 | |||
| 95 | public function __construct(string $sub) |
||
| 96 | { |
||
| 97 | $this->sub = $sub; |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @return string |
||
| 102 | */ |
||
| 103 | public function getSub(): string |
||
| 104 | { |
||
| 105 | return $this->sub; |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @return null|string |
||
| 110 | */ |
||
| 111 | public function getName(): ?string |
||
| 112 | { |
||
| 113 | return $this->name; |
||
| 114 | } |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @param null|string $name |
||
| 118 | */ |
||
| 119 | public function setName(?string $name) |
||
| 120 | { |
||
| 121 | $this->name = $name; |
||
| 122 | } |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @return null|string |
||
| 126 | */ |
||
| 127 | public function getGivenName(): ?string |
||
| 128 | { |
||
| 129 | return $this->givenName; |
||
| 130 | } |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @param null|string $givenName |
||
| 134 | */ |
||
| 135 | public function setGivenName(?string $givenName) |
||
| 136 | { |
||
| 137 | $this->givenName = $givenName; |
||
| 138 | } |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @return null|string |
||
| 142 | */ |
||
| 143 | public function getFamilyName(): ?string |
||
| 144 | { |
||
| 145 | return $this->familyName; |
||
| 146 | } |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @param null|string $familyName |
||
| 150 | */ |
||
| 151 | public function setFamilyName(?string $familyName) |
||
| 152 | { |
||
| 153 | $this->familyName = $familyName; |
||
| 154 | } |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @return null|string |
||
| 158 | */ |
||
| 159 | public function getMiddleName(): ?string |
||
| 160 | { |
||
| 161 | return $this->middleName; |
||
| 162 | } |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @param null|string $middleName |
||
| 166 | */ |
||
| 167 | public function setMiddleName(?string $middleName) |
||
| 168 | { |
||
| 169 | $this->middleName = $middleName; |
||
| 170 | } |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @return null|string |
||
| 174 | */ |
||
| 175 | public function getNickname(): ?string |
||
| 176 | { |
||
| 177 | return $this->nickname; |
||
| 178 | } |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @param null|string $nickname |
||
| 182 | */ |
||
| 183 | public function setNickname(?string $nickname) |
||
| 184 | { |
||
| 185 | $this->nickname = $nickname; |
||
| 186 | } |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @return null|string |
||
| 190 | */ |
||
| 191 | public function getPreferredUsername(): ?string |
||
| 192 | { |
||
| 193 | return $this->preferredUsername; |
||
| 194 | } |
||
| 195 | |||
| 196 | /** |
||
| 197 | * @param null|string $preferredUsername |
||
| 198 | */ |
||
| 199 | public function setPreferredUsername(?string $preferredUsername) |
||
| 200 | { |
||
| 201 | $this->preferredUsername = $preferredUsername; |
||
| 202 | } |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @return null|string |
||
| 206 | */ |
||
| 207 | public function getProfile(): ?string |
||
| 210 | } |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @param null|string $profile |
||
| 214 | */ |
||
| 215 | public function setProfile(?string $profile) |
||
| 216 | { |
||
| 217 | $this->profile = $profile; |
||
| 218 | } |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @return null|string |
||
| 222 | */ |
||
| 223 | public function getPicture(): ?string |
||
| 224 | { |
||
| 225 | return $this->picture; |
||
| 226 | } |
||
| 227 | |||
| 228 | /** |
||
| 229 | * @param null|string $picture |
||
| 230 | */ |
||
| 231 | public function setPicture(?string $picture) |
||
| 232 | { |
||
| 233 | $this->picture = $picture; |
||
| 234 | } |
||
| 235 | |||
| 236 | /** |
||
| 237 | * @return null|string |
||
| 238 | */ |
||
| 239 | public function getWebsite(): ?string |
||
| 242 | } |
||
| 243 | |||
| 244 | /** |
||
| 245 | * @param null|string $website |
||
| 246 | */ |
||
| 247 | public function setWebsite(?string $website) |
||
| 248 | { |
||
| 249 | $this->website = $website; |
||
| 250 | } |
||
| 251 | |||
| 252 | /** |
||
| 253 | * @return null|string |
||
| 254 | */ |
||
| 255 | public function getEmail(): ?string |
||
| 256 | { |
||
| 257 | return $this->email; |
||
| 258 | } |
||
| 259 | |||
| 260 | /** |
||
| 261 | * @param null|string $email |
||
| 262 | */ |
||
| 263 | public function setEmail(?string $email) |
||
| 264 | { |
||
| 265 | $this->email = $email; |
||
| 266 | } |
||
| 267 | |||
| 268 | /** |
||
| 269 | * @return null|bool |
||
| 270 | */ |
||
| 271 | public function getEmailVerified(): ?bool |
||
| 272 | { |
||
| 273 | return $this->emailVerified; |
||
| 274 | } |
||
| 275 | |||
| 276 | /** |
||
| 277 | * @param null|bool $emailVerified |
||
| 278 | */ |
||
| 279 | public function setEmailVerified(?bool $emailVerified) |
||
| 280 | { |
||
| 281 | $this->emailVerified = $emailVerified; |
||
| 282 | } |
||
| 283 | |||
| 284 | /** |
||
| 285 | * @return null|string |
||
| 286 | */ |
||
| 287 | public function getGender(): ?string |
||
| 288 | { |
||
| 289 | return $this->gender; |
||
| 290 | } |
||
| 291 | |||
| 292 | /** |
||
| 293 | * @param null|string $gender |
||
| 294 | */ |
||
| 295 | public function setGender(?string $gender) |
||
| 296 | { |
||
| 297 | $this->gender = $gender; |
||
| 298 | } |
||
| 299 | |||
| 300 | /** |
||
| 301 | * @return null|string |
||
| 302 | */ |
||
| 303 | public function getBirthdate(): ?string |
||
| 304 | { |
||
| 305 | return $this->birthdate; |
||
| 306 | } |
||
| 307 | |||
| 308 | /** |
||
| 309 | * @param null|string $birthdate |
||
| 310 | */ |
||
| 311 | public function setBirthdate(?string $birthdate) |
||
| 312 | { |
||
| 313 | $this->birthdate = $birthdate; |
||
| 314 | } |
||
| 315 | |||
| 316 | /** |
||
| 317 | * @return null|string |
||
| 318 | */ |
||
| 319 | public function getZoneinfo(): ?string |
||
| 320 | { |
||
| 321 | return $this->zoneinfo; |
||
| 322 | } |
||
| 323 | |||
| 324 | /** |
||
| 325 | * @param null|string $zoneinfo |
||
| 326 | */ |
||
| 327 | public function setZoneinfo(?string $zoneinfo) |
||
| 328 | { |
||
| 329 | $this->zoneinfo = $zoneinfo; |
||
| 330 | } |
||
| 331 | |||
| 332 | /** |
||
| 333 | * @return null|string |
||
| 334 | */ |
||
| 335 | public function getLocale(): ?string |
||
| 336 | { |
||
| 337 | return $this->locale; |
||
| 338 | } |
||
| 339 | |||
| 340 | /** |
||
| 341 | * @param null|string $locale |
||
| 342 | */ |
||
| 343 | public function setLocale(?string $locale) |
||
| 346 | } |
||
| 347 | |||
| 348 | /** |
||
| 349 | * @return null|string |
||
| 350 | */ |
||
| 351 | public function getPhoneNumber(): ?string |
||
| 354 | } |
||
| 355 | |||
| 356 | /** |
||
| 357 | * @param null|string $phoneNumber |
||
| 358 | */ |
||
| 359 | public function setPhoneNumber(?string $phoneNumber) |
||
| 360 | { |
||
| 361 | $this->phoneNumber = $phoneNumber; |
||
| 362 | } |
||
| 363 | |||
| 364 | /** |
||
| 365 | * @return null|bool |
||
| 366 | */ |
||
| 367 | public function getPhoneNumberVerified(): ?bool |
||
| 370 | } |
||
| 371 | |||
| 372 | /** |
||
| 373 | * @param null|bool $phoneNumberVerified |
||
| 374 | */ |
||
| 375 | public function setPhoneNumberVerified(?bool $phoneNumberVerified) |
||
| 376 | { |
||
| 377 | $this->phoneNumberVerified = $phoneNumberVerified; |
||
| 378 | } |
||
| 379 | |||
| 380 | /** |
||
| 381 | * @return null|AddressClaim |
||
| 382 | */ |
||
| 383 | public function getAddress(): ?AddressClaim |
||
| 384 | { |
||
| 385 | return $this->address; |
||
| 386 | } |
||
| 387 | |||
| 388 | /** |
||
| 389 | * @param null|AddressClaim $address |
||
| 390 | */ |
||
| 391 | public function setAddress(?AddressClaim $address) |
||
| 392 | { |
||
| 393 | $this->address = $address; |
||
| 394 | } |
||
| 395 | |||
| 396 | /** |
||
| 397 | * @return null|string |
||
| 398 | */ |
||
| 399 | public function getUpdatedAt(): ?string |
||
| 400 | { |
||
| 401 | return $this->updatedAt; |
||
| 402 | } |
||
| 403 | |||
| 404 | /** |
||
| 405 | * @param null|string $updatedAt |
||
| 406 | */ |
||
| 407 | public function setUpdatedAt(?string $updatedAt) |
||
| 408 | { |
||
| 409 | $this->updatedAt = $updatedAt; |
||
| 410 | } |
||
| 411 | |||
| 412 | private function snakeToCamel($offset) { |
||
| 413 | return preg_replace_callback('/_(.?)/', function($matches) { |
||
| 414 | return ucfirst($matches[1]); |
||
| 415 | }, $offset); |
||
| 416 | } |
||
| 417 | |||
| 418 | /** |
||
| 419 | * Whether a offset exists |
||
| 420 | * @link http://php.net/manual/en/arrayaccess.offsetexists.php |
||
| 421 | * @param mixed $offset <p> |
||
| 422 | * An offset to check for. |
||
| 423 | * </p> |
||
| 424 | * @return boolean true on success or false on failure. |
||
| 425 | * </p> |
||
| 426 | * <p> |
||
| 427 | * The return value will be casted to boolean if non-boolean was returned. |
||
| 428 | * @since 5.0.0 |
||
| 429 | */ |
||
| 430 | public function offsetExists($offset) |
||
| 433 | } |
||
| 434 | |||
| 435 | /** |
||
| 436 | * Offset to retrieve |
||
| 437 | * @link http://php.net/manual/en/arrayaccess.offsetget.php |
||
| 438 | * @param mixed $offset <p> |
||
| 439 | * The offset to retrieve. |
||
| 440 | * </p> |
||
| 441 | * @return mixed Can return all value types. |
||
| 442 | * @since 5.0.0 |
||
| 443 | */ |
||
| 444 | public function offsetGet($offset) |
||
| 445 | { |
||
| 446 | $getter = 'get'.ucfirst($this->snakeToCamel($offset)); |
||
| 447 | $result = $this->{$getter}(); |
||
| 448 | if(is_object($result)) { |
||
| 449 | return json_encode($result); |
||
| 450 | } |
||
| 451 | return $result; |
||
| 452 | } |
||
| 453 | |||
| 454 | /** |
||
| 455 | * Offset to set |
||
| 456 | * @link http://php.net/manual/en/arrayaccess.offsetset.php |
||
| 457 | * @param mixed $offset <p> |
||
| 458 | * The offset to assign the value to. |
||
| 459 | * </p> |
||
| 460 | * @param mixed $value <p> |
||
| 461 | * The value to set. |
||
| 462 | * </p> |
||
| 463 | * @return void |
||
| 464 | * @since 5.0.0 |
||
| 465 | */ |
||
| 466 | public function offsetSet($offset, $value) |
||
| 467 | { |
||
| 468 | $setter = 'set'.ucfirst($this->snakeToCamel($offset)); |
||
| 469 | $this->{$setter}($value); |
||
| 470 | } |
||
| 471 | |||
| 472 | /** |
||
| 473 | * Offset to unset |
||
| 474 | * @link http://php.net/manual/en/arrayaccess.offsetunset.php |
||
| 475 | * @param mixed $offset <p> |
||
| 476 | * The offset to unset. |
||
| 477 | * </p> |
||
| 478 | * @return void |
||
| 479 | * @since 5.0.0 |
||
| 480 | */ |
||
| 481 | public function offsetUnset($offset) |
||
| 485 | } |
||
| 486 | } |