Redmine   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 14
eloc 27
dl 0
loc 81
c 1
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A parseAccessTokenResponse() 0 22 4
A getAuthorizationEndpoint() 0 3 1
A __construct() 0 11 2
A parseRequestTokenResponse() 0 11 5
A getAccessTokenEndpoint() 0 3 1
A getRequestTokenEndpoint() 0 3 1
1
<?php
2
3
namespace OAuth\OAuth1\Service;
4
5
use Exception;
6
use OAuth\Common\Consumer\CredentialsInterface;
7
use OAuth\Common\Http\Client\ClientInterface;
8
use OAuth\Common\Http\Exception\TokenResponseException;
9
use OAuth\Common\Http\Uri\Uri;
10
use OAuth\Common\Http\Uri\UriInterface;
11
use OAuth\Common\Storage\TokenStorageInterface;
12
use OAuth\OAuth1\Signature\SignatureInterface;
13
use OAuth\OAuth1\Token\StdOAuth1Token;
14
15
class Redmine extends AbstractService
16
{
17
    public function __construct(
18
        CredentialsInterface $credentials,
19
        ClientInterface $httpClient,
20
        TokenStorageInterface $storage,
21
        SignatureInterface $signature,
22
        ?UriInterface $baseApiUri = null
23
    ) {
24
        parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri);
25
26
        if (null === $baseApiUri) {
27
            throw new Exception('baseApiUri is a required argument.');
28
        }
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function getRequestTokenEndpoint()
35
    {
36
        return new Uri($this->baseApiUri->getAbsoluteUri() . '/request_token');
0 ignored issues
show
Bug introduced by
The method getAbsoluteUri() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
        return new Uri($this->baseApiUri->/** @scrutinizer ignore-call */ getAbsoluteUri() . '/request_token');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getAuthorizationEndpoint()
43
    {
44
        return new Uri($this->baseApiUri->getAbsoluteUri() . '/authorize');
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function getAccessTokenEndpoint()
51
    {
52
        return new Uri($this->baseApiUri->getAbsoluteUri() . '/access_token');
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    protected function parseRequestTokenResponse($responseBody)
59
    {
60
        parse_str($responseBody, $data);
61
62
        if (null === $data || !is_array($data)) {
63
            throw new TokenResponseException('Unable to parse response.');
64
        } elseif (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') {
65
            throw new TokenResponseException('Error in retrieving token.');
66
        }
67
68
        return $this->parseAccessTokenResponse($responseBody);
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    protected function parseAccessTokenResponse($responseBody)
75
    {
76
        parse_str($responseBody, $data);
77
78
        if (null === $data || !is_array($data)) {
79
            throw new TokenResponseException('Unable to parse response.');
80
        } elseif (isset($data['error'])) {
81
            throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
82
        }
83
84
        $token = new StdOAuth1Token();
85
86
        $token->setRequestToken($data['oauth_token']);
87
        $token->setRequestTokenSecret($data['oauth_token_secret']);
88
        $token->setAccessToken($data['oauth_token']);
89
        $token->setAccessTokenSecret($data['oauth_token_secret']);
90
91
        $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
92
        unset($data['oauth_token'], $data['oauth_token_secret']);
93
        $token->setExtraParams($data);
94
95
        return $token;
96
    }
97
}
98