SePayIdentityProviderException::clientException()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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