Skip to content

Commit

Permalink
[Twitter] Up code quality - getIdentity is now more safety
Browse files Browse the repository at this point in the history
  • Loading branch information
ovr committed Feb 5, 2017
1 parent c249d32 commit 24be857
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions providers/Twitter/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace SocialConnect\Twitter;

use SocialConnect\Auth\Exception\InvalidResponse;
use SocialConnect\Auth\Provider\OAuth1\AccessToken;
use SocialConnect\Common\Entity\User;
use SocialConnect\Common\Http\Client\Client;
Expand Down Expand Up @@ -55,17 +56,27 @@ public function getIdentity(AccessToken $accessToken)
$this->requestTokenHeaders
);

if ($response->getStatusCode() == 200) {
$result = $response->json();
if (!$response->isSuccess()) {
throw new InvalidResponse(
'API response with error code',
$response
);
}

$hydrator = new ObjectMap(array(
'id' => 'id',
'name' => 'fullname',
'screen_name' => 'username'
));
return $hydrator->hydrate(new User(), $result[0]);
$result = $response->json();
if (!$result) {
throw new InvalidResponse(
'API response is not a valid JSON object',
$response->getBody()
);
}

return false;
$hydrator = new ObjectMap(array(
'id' => 'id',
'name' => 'fullname',
'screen_name' => 'username'
));

return $hydrator->hydrate(new User(), $result[0]);
}
}

0 comments on commit 24be857

Please sign in to comment.