anonymous//Client/EncodingTrait.php$0
last analyzed

Complexity

Total Complexity 0

Size/Duplication

Total Lines 4
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
ccs 1
cts 1
cp 1
wmc 0
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