Test Setup Failed
Push — master ( 9f9cb8...fab90b )
by Patrick
03:08
created

Mailxpert   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 13
dl 0
loc 80
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getResourceOwnerDetailsUrl() 0 3 1
A getDefaultScopes() 0 3 1
A checkResponse() 0 9 3
A createResourceOwner() 0 3 1
A getBaseAccessTokenUrl() 0 3 1
A getBaseAuthorizationUrl() 0 3 1
1
<?php
2
3
namespace Mailxpert\OAuth2\Client\Provider;
4
5
use League\OAuth2\Client\Provider\AbstractProvider;
6
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
7
use League\OAuth2\Client\Token\AccessToken;
8
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
9
use Mailxpert\OAuth2\Client\Exception\ResourceOwnerException;
10
use Psr\Http\Message\ResponseInterface;
11
12
class Mailxpert extends AbstractProvider
13
{
14
    use BearerAuthorizationTrait;
15
16
    /**
17
     * Get authorization url to begin OAuth 2.0 'Authorization Code' grant.
18
     *
19
     * @return string
20
     */
21
    public function getBaseAuthorizationUrl()
22
    {
23
        return 'https://v5.mailxpert.ch/oauth/v2/auth';
24
    }
25
26
    /**
27
     * Get access token url to retrieve token.
28
     *
29
     * @param array $params
30
     *
31
     * @return string
32
     */
33
    public function getBaseAccessTokenUrl(array $params)
34
    {
35
        return 'https://v5.mailxpert.ch/oauth/v2/token';
36
    }
37
38
    /**
39
     * We do currently not support an owner resource.
40
     *
41
     * @param AccessToken $token
42
     *
43
     * @throws ResourceOwnerException
44
     *
45
     * @return string|void
46
     */
47
    public function getResourceOwnerDetailsUrl(AccessToken $token)
48
    {
49
        throw new ResourceOwnerException();
50
    }
51
52
    /**
53
     * Get the default scopes uses by this provider. Currently there is no support of scopes at all thus returning an empty array.
54
     *
55
     * @return array
56
     */
57
    protected function getDefaultScopes()
58
    {
59
        return [];
60
    }
61
62
    /**
63
     * @param ResponseInterface $response
64
     * @param array|string      $data
65
     *
66
     * @throws IdentityProviderException
67
     */
68
    protected function checkResponse(ResponseInterface $response, $data)
69
    {
70
        $statusCode = $response->getStatusCode();
71
72
        if ($statusCode >= 400) {
73
            throw new IdentityProviderException(
74
                isset($data['message']) ? $data['message'] : $response->getReasonPhrase(),
75
                $statusCode,
76
                $response
0 ignored issues
show
Bug introduced by
$response of type Psr\Http\Message\ResponseInterface is incompatible with the type array|string expected by parameter $response of League\OAuth2\Client\Pro...xception::__construct(). ( Ignorable by Annotation )

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

76
                /** @scrutinizer ignore-type */ $response
Loading history...
77
            );
78
        }
79
    }
80
81
    /**
82
     * @param array       $response
83
     * @param AccessToken $token
84
     *
85
     * @throws ResourceOwnerException
86
     *
87
     * @return \League\OAuth2\Client\Provider\ResourceOwnerInterface|void
88
     */
89
    protected function createResourceOwner(array $response, AccessToken $token)
90
    {
91
        throw new ResourceOwnerException();
92
    }
93
}
94