EncodingTrait.php$0 ➔ withEncoding()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
c 0
b 0
f 0
dl 0
loc 10
ccs 4
cts 4
cp 1
crap 2
rs 9.9332
1
<?php
2
3
/*
4
 * This file is part of the Koded package.
5
 *
6
 * (c) Mihail Binev <[email protected]>
7
 *
8
 * Please view the LICENSE distributed with this source code
9
 * for the full copyright and license information.
10
 *
11
 */
12
13
namespace Koded\Http\Client;
14
15
use Koded\Http\Interfaces\HttpStatus;
16
use Psr\Http\Client\ClientExceptionInterface;
17
18
trait EncodingTrait
19
{
20
    private int $encoding = PHP_QUERY_RFC3986;
21
22
    public function withEncoding(int $type): static
23
    {
24 10
        if (\in_array($type, [0, PHP_QUERY_RFC1738, PHP_QUERY_RFC3986], true)) {
25
            $this->encoding = $type;
26 10
            return $this;
27 8
        }
28
        throw new class(
29 8
            'Invalid encoding type. Expects 0, PHP_QUERY_RFC1738 or PHP_QUERY_RFC3986',
30
            HttpStatus::BAD_REQUEST
31
        ) extends \Exception implements ClientExceptionInterface {};
32
    }
33
}
34