Completed
Pull Request — master (#144)
by
unknown
12:31
created

FacebookUserProvider::getUser()   A

Complexity

Conditions 2
Paths 4

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 12
nc 4
nop 1
dl 0
loc 18
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace AppBundle\Services;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Exception\TransferException;
7
use Symfony\Component\HttpKernel\Exception\HttpException;
8
9
class FacebookUserProvider
10
{
11
    /**
12
     * @param string $accessToken
13
     *
14
     * @return mixed
15
     */
16
    public function getUser($accessToken)
17
    {
18
        try {
19
            $client = new Client();
20
            $result = $client->get(
21
                'https://graph.facebook.com/v2.8/me',
22
                ['query' => [
23
                    'access_token' => $accessToken,
24
                    'fields' => 'id, email, first_name, last_name', ],
25
                ]
26
            );
27
            $userFacebook = json_decode($result->getBody());
28
29
            return $userFacebook;
30
        } catch (TransferException $e) {
31
            throw new HttpException(400, 'Social login error');
32
        }
33
    }
34
}
35