| Total Complexity | 9 |
| Total Lines | 121 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | class DraugiemUserInterface implements ResourceOwnerInterface, SocialUserInterface |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var array |
||
| 12 | */ |
||
| 13 | protected $response; |
||
| 14 | |||
| 15 | protected $userData; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var integer |
||
| 19 | */ |
||
| 20 | protected $id; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | protected $email; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | protected $firstName; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | protected $lastName; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | protected $username; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param array $response |
||
| 44 | */ |
||
| 45 | public function __construct(array $response) |
||
| 46 | { |
||
| 47 | $this->response = $response; |
||
| 48 | $this->userData = reset($this->response['users']); |
||
| 49 | |||
| 50 | $this->id = intval($this->response['uid']); |
||
| 51 | |||
| 52 | $this->firstName = $this->getField('name'); |
||
| 53 | |||
| 54 | $this->lastName = $this->getField('surname'); |
||
| 55 | |||
| 56 | $this->username = preg_replace('/[^a-z\d]/i', '', $this->getField('url')); |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Returns all the data obtained about the user. |
||
| 61 | * |
||
| 62 | * @return array |
||
| 63 | */ |
||
| 64 | public function toArray() |
||
| 65 | { |
||
| 66 | return $this->response; |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Returns a field from the Graph node data. |
||
| 71 | * |
||
| 72 | * @param string $key |
||
| 73 | * |
||
| 74 | * @return mixed|null |
||
| 75 | */ |
||
| 76 | private function getField($key) |
||
| 77 | { |
||
| 78 | return isset($this->userData[$key]) ? $this->userData[$key] : null; |
||
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Get the value of Id |
||
| 83 | * |
||
| 84 | * @return integer |
||
| 85 | */ |
||
| 86 | public function getId() |
||
| 87 | { |
||
| 88 | return $this->id; |
||
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Get the value of Email |
||
| 93 | * |
||
| 94 | * @return string |
||
| 95 | */ |
||
| 96 | public function getEmail() |
||
| 97 | { |
||
| 98 | return $this->email; |
||
| 99 | } |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Get the value of First Name |
||
| 103 | * |
||
| 104 | * @return string |
||
| 105 | */ |
||
| 106 | public function getFirstName() |
||
| 107 | { |
||
| 108 | return $this->firstName; |
||
| 109 | } |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Get the value of Last Name |
||
| 113 | * |
||
| 114 | * @return string |
||
| 115 | */ |
||
| 116 | public function getLastName() |
||
| 117 | { |
||
| 118 | return $this->lastName; |
||
| 119 | } |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Get the value of Username |
||
| 123 | * |
||
| 124 | * @return string |
||
| 125 | */ |
||
| 126 | public function getUsername() |
||
| 129 | } |
||
| 130 | } |
||
| 131 |