EvernoteOauth   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 48
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B authorize() 0 42 6
1
<?php
2
3
namespace Evernote\Auth;
4
5
class EvernoteOauth extends \Evernote\Auth\OauthHandler
6
{
7
    protected $params = array();
8
9
    public function authorize($consumer_key, $consumer_secret, $callback)
0 ignored issues
show
Coding Style introduced by
authorize uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
10
    {
11
        $this->params['oauth_callback']         = $callback;
12
        $this->params['oauth_consumer_key']     = $consumer_key;
13
14
        $this->consumer_secret = $consumer_secret;
15
16
        // first call
17
        if (!array_key_exists('oauth_verifier', $_GET) && !array_key_exists('oauth_token', $_GET)) {
18
19
            unset($this->params['oauth_token']);
20
            unset($this->params['oauth_verifier']);
21
22
            $temporaryCredentials = $this->getTemporaryCredentials();
23
24
            Session::set('oauth_token_secret', $temporaryCredentials['oauth_token_secret']);
25
26
            $authorizationUrl = 'Location: '
27
                . $this->getBaseUrl('OAuth.action?oauth_token=')
28
                . $temporaryCredentials['oauth_token'];
29
30
            if ($this->supportLinkedSandbox) {
31
                $authorizationUrl .= '&supportLinkedSandbox=true';
32
            }
33
34
            header($authorizationUrl);
35
36
            // the user declined the authorization
37
        } elseif (!array_key_exists('oauth_verifier', $_GET) && array_key_exists('oauth_token', $_GET)) {
38
            throw new AuthorizationDeniedException('Authorization declined.');
39
            //the user authorized the app
40
        } else {
41
            $this->token_secret = Session::get('oauth_token_secret');
42
43
            $this->params['oauth_token']    = $_GET['oauth_token'];
44
            $this->params['oauth_verifier'] = $_GET['oauth_verifier'];
45
            unset($this->params['oauth_callback']);
46
47
            return $this->getTemporaryCredentials();
48
        }
49
50
    }
51
52
}