oauthException()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 1
nop 2
dl 0
loc 7
ccs 0
cts 7
cp 0
crap 6
rs 10
c 0
b 0
f 0
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
}