Completed
Push — master ( 53dd23...58e367 )
by BENOIT
01:13
created

NativeRenderer::withEncoding()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace BenTools\QueryString\Renderer;
4
5
use BenTools\QueryString\QueryString;
6
7
final class NativeRenderer implements QueryStringRendererInterface
8
{
9
    use QueryStringRendererTrait;
10
11
    /**
12
     * NativeRenderer constructor.
13
     * @param int $encoding
14
     */
15
    protected function __construct(int $encoding)
16
    {
17
        $this->encoding = $encoding;
18
    }
19
20
    /**
21
     * @param int $encoding
22
     * @return NativeRenderer
23
     * @throws \InvalidArgumentException
24
     */
25
    public static function factory(int $encoding = self::DEFAULT_ENCODING): self
26
    {
27
        self::validateEncoding($encoding);
28
29
        return new self($encoding);
30
    }
31
32
33
    /**
34
     * @inheritDoc
35
     */
36
    public function render(QueryString $queryString): string
37
    {
38
        return http_build_query(
39
            $queryString->getParams(),
40
            null,
41
            $this->separator ?? ini_get('arg_separator.output'),
42
            $this->encoding
43
        );
44
    }
45
}
46