Total Complexity | 7 |
Total Lines | 57 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | class Encode |
||
11 | { |
||
12 | /** |
||
13 | * @var array |
||
14 | */ |
||
15 | private $data; |
||
16 | |||
17 | /** |
||
18 | * @param array $data |
||
19 | * |
||
20 | * @return static |
||
21 | */ |
||
22 | 54 | public static function create(array $data) |
|
23 | { |
||
24 | 54 | return new static($data); |
|
25 | } |
||
26 | |||
27 | /** |
||
28 | * Encode constructor. |
||
29 | * |
||
30 | * @param array $data |
||
31 | */ |
||
32 | 54 | private function __construct(array $data) |
|
35 | 54 | } |
|
36 | |||
37 | /** |
||
38 | * @return bool|string |
||
39 | */ |
||
40 | 54 | public function toString() |
|
41 | { |
||
42 | 54 | $string = ''; |
|
43 | 54 | foreach ($this->data as $key => $value) { |
|
44 | 54 | $encode = rawurlencode($value); |
|
45 | 54 | if ($encode === '') { |
|
46 | 54 | $string .= "$key&"; |
|
47 | } else { |
||
48 | 54 | $string .= "$key=$encode&"; |
|
49 | 54 | } |
|
50 | 54 | } |
|
51 | |||
52 | 54 | if (0 < count($this->data)) { |
|
53 | $string = substr($string, 0, -1); |
||
54 | } |
||
55 | |||
56 | return $string; |
||
57 | } |
||
58 | 18 | ||
59 | /** |
||
60 | 18 | * @return $this |
|
61 | */ |
||
62 | 18 | public function ksort() |
|
67 | } |
||
68 | } |
||
69 |