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

Mock::setAuthorizationMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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