oauthException()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 4
nc 1
nop 2
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: xiabin
5
 * Date: 16/6/24
6
 * Time: 下午7:12
7
 */
8
namespace Xiabin\OAuth2\Client\Provider\Exception;
9
10
use Psr\Http\Message\ResponseInterface;
11
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
12
13
class SinaWeiboIdentityProviderException extends IdentityProviderException
14
{
15
    /**
16
     * Creates client exception from response.
17
     *
18
     * @param  ResponseInterface $response
19
     * @param  string $data Parsed response data
20
     *
21
     * @return IdentityProviderException
22
     */
23 3
    public static function clientException(ResponseInterface $response, $data)
24
    {
25 3
        return static::fromResponse(
26 2
            $response,
27 3
            isset($data['message']) ? $data['message'] : $response->getReasonPhrase()
28 2
        );
29
    }
30
31
    /**
32
     * Creates oauth exception from response.
33
     *
34
     * @param  ResponseInterface $response
35
     * @param  string $data Parsed response data
36
     *
37
     * @return IdentityProviderException
38
     */
39 3
    public static function oauthException(ResponseInterface $response, $data)
40
    {
41 3
        return static::fromResponse(
42 2
            $response,
43 3
            isset($data['error']) ? $data['error'] : $response->getReasonPhrase()
44 2
        );
45
    }
46
47
    /**
48
     * Creates identity exception from response.
49
     *
50
     * @param  ResponseInterface $response
51
     * @param  string $message
52
     *
53
     * @return IdentityProviderException
54
     */
55 6
    protected static function fromResponse(ResponseInterface $response, $message = null)
56
    {
57 6
        return new static($message, $response->getStatusCode(), (string)$response->getBody());
58
    }
59
}
60