Completed
Pull Request — master (#137)
by
unknown
12:51
created

FacebookSdk   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 42
rs 10
wmc 5
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B setValue() 0 24 3
A getValue() 0 4 1
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
    public $accessToken;
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 setValue($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,name,email');
32
33
            $this->userNode = $response->getGraphUser();
34
        } catch (Facebook\Exceptions\FacebookResponseException $e) {
0 ignored issues
show
Bug introduced by
The class Facebook\Exceptions\FacebookResponseException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
35
            // When Graph returns an error
36
         echo 'Graph returned an error: '.$e->getMessage();
37
            exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method setValue() 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...
38
        } catch (Facebook\Exceptions\FacebookSDKException $e) {
0 ignored issues
show
Bug introduced by
The class Facebook\Exceptions\FacebookSDKException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
39
            // When validation fails or other local issues
40
         echo 'Facebook SDK returned an error: '.$e->getMessage();
41
            exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method setValue() 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...
42
        }
43
    }
44
    public function getValue()
45
    {
46
        return $this->userNode;
47
    }
48
}
49