YConnectIdentityProviderException   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 47
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A clientException() 0 7 3
A oauthException() 0 7 2
A fromResponse() 0 4 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: polidog
5
 * Date: 2016/11/09
6
 */
7
8
namespace Tavii\OAuth2\Client\Provider\Exception;
9
10
11
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
12
use Psr\Http\Message\ResponseInterface;
13
14
class YConnectIdentityProviderException extends IdentityProviderException
15
{
16
    /**
17
     * Creates client exception from response.
18
     *
19
     * @param ResponseInterface $response
20
     * @param array             $data
21
     *
22
     * @return YConnectIdentityProviderException
23
     */
24
    public static function clientException(ResponseInterface $response, array $data)
25
    {
26
        return static::fromResponse(
27
            $response,
28
            isset($data['error']) && isset($data['error_description']) ? $data['error'].': '.$data['error_description'] : $response->getReasonPhrase()
29
        );
30
    }
31
32
    /**
33
     * Creates oauth exception from response.
34
     *
35
     * @param ResponseInterface $response
36
     * @param array             $data
37
     *
38
     * @return YConnectIdentityProviderException
39
     */
40
    public static function oauthException(ResponseInterface $response, array $data)
41
    {
42
        return static::fromResponse(
43
            $response,
44
            isset($data['error']) ? $data['error'] : $response->getReasonPhrase()
45
        );
46
    }
47
48
    /**
49
     * Creates identity exception from response.
50
     *
51
     * @param ResponseInterface $response
52
     * @param null              $message
53
     *
54
     * @return static
55
     */
56
    protected static function fromResponse(ResponseInterface $response, $message = null)
57
    {
58
        return new static($message, $response->getStatusCode(), (string) $response->getBody());
59
    }
60
}