Passed
Push — master ( 5620bf...f38109 )
by Eric
01:56
created

RateLimitExceededException   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 21
rs 10
ccs 13
cts 13
cp 1
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 1
A getResponse() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Esi\LibrariesIO.
7
 *
8
 * (c) 2023-2024 Eric Sizemore <https://github.com/ericsizemore>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13
14
namespace Esi\LibrariesIO\Exception;
15
16
use GuzzleHttp\Exception\ClientException;
17
use Psr\Http\Message\RequestInterface;
18
use Psr\Http\Message\ResponseInterface;
19
use RuntimeException;
20
21
use function vsprintf;
22
23
/**
24
 * RateLimitExceededException.
25
 */
26
final class RateLimitExceededException extends RuntimeException
27
{
28 2
    public function __construct(private readonly ClientException $clientException)
29
    {
30 2
        $request = $clientException->getRequest();
31
32 2
        $message = vsprintf(
33 2
            'Libraries.io Rate Limit Exceeded. Limit: %s, Remaining: %s, Reset: %s',
34 2
            [
35 2
                $request->getHeaderLine('x-ratelimit-limit'),
36 2
                $request->getHeaderLine('x-ratelimit-remaining'),
37 2
                $request->getHeaderLine('x-ratelimit-reset'),
38 2
            ]
39 2
        );
40
41 2
        parent::__construct($message, 0, $clientException);
42
    }
43
44 2
    public function getResponse(): ResponseInterface
45
    {
46 2
        return $this->clientException->getResponse();
47
    }
48
}
49