Passed
Branch master (c65ffc)
by Dāvis
03:08
created

CustomIdentityProviderException::fromResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sludio\HelperBundle\Oauth\Exception;
4
5
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
6
use Psr\Http\Message\ResponseInterface;
7
8
class CustomIdentityProviderException extends IdentityProviderException
9
{
10
    public static function clientException(ResponseInterface $response, $data)
11
    {
12
        return static::fromResponse($response, isset($data['message']) ? $data['message'] : $response->getReasonPhrase());
13
    }
14
15
    public static function oauthException(ResponseInterface $response, $data)
16
    {
17
        return static::fromResponse($response, isset($data['error']) ? $data['error'] : $response->getReasonPhrase());
18
    }
19
20
    protected static function fromResponse(ResponseInterface $response, $message = null)
21
    {
22
        return new static($message, $response->getStatusCode(), (string)$response->getBody());
23
    }
24
}
25