Completed
Pull Request — master (#137)
by
unknown
11:18
created

FacebookSdk::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 4
c 2
b 0
f 1
nc 1
nop 3
dl 0
loc 6
rs 9.4285
1
<?php
2
3
namespace AppBundle\Services;
4
5
use Facebook;
6
7
class FacebookSdk
8
{
9
    private $userNode;
10
    private $appId;
11
    private $appSecret;
12
    private $graf_version;
13
14
    public function __construct($appId, $appSecret, $graf_version)
15
    {
16
        $this->appId = $appId;
17
        $this->appSecret = $appSecret;
18
        $this->graf_version = $graf_version;
19
    }
20
    public function getUserFacebook($accessToken)
21
    {
22
        $fb = new \Facebook\Facebook([
23
24
            'app_id' => $this->appId,
25
            'app_secret' => $this->appSecret,
26
            'default_graph_version' => $this->graf_version,
27
        ]);
28
        $fb->setDefaultAccessToken($accessToken);
29
30
        try {
31
            $response = $fb->get('/me?fields=id,email,first_name, last_name');
32
            // $userNode = $response->getGraphUser();
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
33
            $this->userNode = $response->getGraphUser();
34
35
            return $this->userNode;
36
        } catch (Facebook\Exceptions\FacebookResponseException $e) {
37
            // When Graph returns an error
38
            echo 'Graph returned an error: '.$e->getMessage();
39
            exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method getUserFacebook() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
40
        } catch (Facebook\Exceptions\FacebookSDKException $e) {
41
            // When validation fails or other local issues
42
            echo 'Facebook SDK returned an error: '.$e->getMessage();
43
            exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method getUserFacebook() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
44
        }
45
    }
46
    public function getValue()
47
    {
48
        return $this->userNode;
49
    }
50
}
51