| Conditions | 6 | 
| Paths | 8 | 
| Total Lines | 23 | 
| Code Lines | 15 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Tests | 19 | 
| CRAP Score | 6 | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
| 1 | <?php | ||
| 42 | 4 | public function getToken() | |
| 43 |     { | ||
| 44 | 4 |         if (!is_null($this->token) && $this->token->isExpired()) { | |
| 45 | 1 | $this->token = null; | |
| 46 | 1 | } | |
| 47 | |||
| 48 | 4 |         if (is_null($this->token)) { | |
| 49 | 4 | $response = $this->gigya->socialize()->getToken([ | |
| 50 | 4 | 'grant_type' => 'none', | |
| 51 | 4 | ], ['auth' => 'credentials']); | |
| 52 | 4 |             if ($response->getErrorCode() == ErrorCode::OK) { | |
| 53 | 3 | $data = $response->getData(); | |
| 54 | 3 |                 $token = $data->get('access_token'); | |
| 55 | 3 | $expires = null; | |
| 56 | 3 |                 if ($data->has('expires_in')) { | |
| 57 | 2 |                     $expires = (new DateTime())->add(new DateInterval(sprintf('PT%dS', $data->get('expires_in', 0)))); | |
| 58 | 2 | } | |
| 59 | 3 | $this->token = new AccessToken($token, $expires); | |
| 60 | 3 | } | |
| 61 | 4 | } | |
| 62 | |||
| 63 | 4 | return $this->token; | |
| 64 | } | ||
| 65 | } | ||
| 66 |