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

RateLimitExceededException::__construct()   A

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\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