Completed
Pull Request — master (#479)
by Andrey
03:26
created

Mock   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 50
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getAuthorizationEndpoint() 0 4 1
A getAccessTokenEndpoint() 0 4 1
A parseAccessTokenResponse() 0 4 1
A setAuthorizationMethod() 0 4 1
A getAuthorizationMethod() 0 15 4
1
<?php
2
3
namespace OAuthTest\Mocks\OAuth2\Service;
4
5
use OAuth\OAuth2\Service\AbstractService;
6
use OAuth\Common\Http\Uri\Uri;
7
use OAuth\OAuth2\Token\StdOAuth2Token;
8
9
class Mock extends AbstractService
10
{
11
    const SCOPE_MOCK   = 'mock';
12
    const SCOPE_MOCK_2 = 'mock2';
13
14
    private $authorizationMethod = null;
15
16
    public function getAuthorizationEndpoint()
17
    {
18
        return new Uri('http://pieterhordijk.com/auth');
19
    }
20
21
    public function getAccessTokenEndpoint()
22
    {
23
        return new Uri('http://pieterhordijk.com/access');
24
    }
25
26
    protected function parseAccessTokenResponse($responseBody)
27
    {
28
        return new StdOAuth2Token();
29
    }
30
31
    // this allows us to set different auth methods for tests
32
    public function setAuthorizationMethod($method)
33
    {
34
        $this->authorizationMethod = $method;
35
    }
36
37
    /**
38
     * Returns a class constant from ServiceInterface defining the authorization method used for the API
39
     * Header is the sane default.
40
     *
41
     * @return int
42
     */
43
    protected function getAuthorizationMethod()
44
    {
45
        switch($this->authorizationMethod) {
46
            case 'querystring':
47
                return static::AUTHORIZATION_METHOD_QUERY_STRING;
48
49
            case 'querystring2':
50
                return static::AUTHORIZATION_METHOD_QUERY_STRING_V2;
51
52
            case 'bearer':
53
                return static::AUTHORIZATION_METHOD_HEADER_BEARER;
54
        }
55
56
        return parent::getAuthorizationMethod();
57
    }
58
}
59