RateLimitExceededException   A
last analyzed

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\ResponseInterface;
18
use RuntimeException;
19
20
use function vsprintf;
21
22
/**
23
 * RateLimitExceededException.
24
 */
25
final class RateLimitExceededException extends RuntimeException
26
{
27 2
    public function __construct(private readonly ClientException $clientException)
28
    {
29 2
        $request = $clientException->getRequest();
30
31 2
        $message = vsprintf(
32 2
            'Libraries.io Rate Limit Exceeded. Limit: %s, Remaining: %s, Reset: %s',
33 2
            [
34 2
                $request->getHeaderLine('x-ratelimit-limit'),
35 2
                $request->getHeaderLine('x-ratelimit-remaining'),
36 2
                $request->getHeaderLine('x-ratelimit-reset'),
37 2
            ]
38 2
        );
39
40 2
        parent::__construct($message, $clientException->getCode(), $clientException);
41
    }
42
43 2
    public function getResponse(): ResponseInterface
44
    {
45 2
        return $this->clientException->getResponse();
46
    }
47
}
48