Completed
Pull Request — master (#137)
by
unknown
15:28
created

FacebookSdk   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B getUserFacebook() 0 26 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
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) {
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...
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) {
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...
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