RateLimitExceededException::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 14
rs 10
ccs 11
cts 11
cp 1
crap 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