Passed
Push — master ( a99737...029358 )
by Dominik
02:01
created

UrlEncodedFormatter::format()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Serialization\Formatter;
6
7
final class UrlEncodedFormatter implements FormatterInterface
8
{
9
    /**
10
     * @var string
11
     */
12
    private $numericPrefix;
13
14
    /**
15
     * @var string
16
     */
17
    private $argSeperator;
18
19
    /**
20
     * @var int
21
     */
22
    private $encType;
23
24
    /**
25
     * @param null|string $numericPrefix
26
     * @param null|string $argSeperator
27
     * @param int|null    $encType
28
     */
29 1
    public function __construct(
30
        string $numericPrefix = '',
31
        string $argSeperator = '&',
32
        int $encType = PHP_QUERY_RFC1738
33
    ) {
34 1
        $this->numericPrefix = $numericPrefix;
35 1
        $this->argSeperator = $argSeperator;
36 1
        $this->encType = $encType;
37 1
    }
38
39
    /**
40
     * @param array $data
41
     *
42
     * @return string
43
     */
44 1
    public function format(array $data): string
45
    {
46 1
        return http_build_query($data, $this->numericPrefix, $this->argSeperator, $this->encType);
47
    }
48
}
49