QueryParamHandler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 6
loc 6
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
/*
3
 * Copyright (c) Nate Brunette.
4
 * Distributed under the MIT License (http://opensource.org/licenses/MIT)
5
 */
6
7
declare(strict_types=1);
8
9
namespace Tebru\Retrofit\Internal\ParameterHandler;
10
11
use Tebru\Retrofit\Internal\RequestBuilder;
12
use Tebru\Retrofit\StringConverter;
13
14
/**
15
 * Class QueryParamHandler
16
 *
17
 * @author Nate Brunette <[email protected]>
18
 */
19 View Code Duplication
final class QueryParamHandler extends AbstractParameterHandler
20
{
21
    /**
22
     * @var StringConverter
23
     */
24
    private $converter;
25
26
    /**
27
     * @var string
28
     */
29
    private $name;
30
31
    /**
32
     * @var bool
33
     */
34
    private $encoded;
35
36
    /**
37
     * Constructor
38
     *
39
     * @param string $name
40
     * @param StringConverter $converter
41
     * @param bool $encoded
42
     */
43 9
    public function __construct(StringConverter $converter, string $name, bool $encoded)
44
    {
45 9
        $this->converter = $converter;
46 9
        $this->name = $name;
47 9
        $this->encoded = $encoded;
48 9
    }
49
50
    /**
51
     * Set a value to the [@see RequestBuilder] for parameter type
52
     *
53
     * @param RequestBuilder $requestBuilder
54
     * @param mixed $value
55
     * @return void
56
     * @throws \RuntimeException
57
     */
58 7
    public function apply(RequestBuilder $requestBuilder, $value): void
59
    {
60 7
        if ($value === null) {
61 2
            return;
62
        }
63
64 5
        foreach ($this->getListValues($value) as $element) {
65 5
            $requestBuilder->addQuery($this->name, $this->converter->convert($element), $this->encoded);
66
        }
67 5
    }
68
}
69