Passed
Branch master (203e41)
by Nate
01:56
created

QueryNameParamHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 5
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 5
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
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 QueryNameParamHandler
16
 *
17
 * @author Nate Brunette <[email protected]>
18
 */
19 View Code Duplication
final class QueryNameParamHandler extends AbstractParameterHandler
20
{
21
    /**
22
     * @var StringConverter
23
     */
24
    private $converter;
25
26
    /**
27
     * @var bool
28
     */
29
    private $encoded;
30
31
    /**
32
     * Constructor
33
     *
34
     * @param StringConverter $converter
35
     * @param bool $encoded
36
     */
37 5
    public function __construct(StringConverter $converter, bool $encoded)
38
    {
39 5
        $this->converter = $converter;
40 5
        $this->encoded = $encoded;
41 5
    }
42
43
    /**
44
     * Set a value to the [@see RequestBuilder] for parameter type
45
     *
46
     * @param RequestBuilder $requestBuilder
47
     * @param mixed $value
48
     * @return void
49
     * @throws \RuntimeException
50
     */
51 4
    public function apply(RequestBuilder $requestBuilder, $value): void
52
    {
53 4
        foreach ($this->getListValues($value) as $element) {
54 3
            $requestBuilder->addQueryName($this->converter->convert($element), $this->encoded);
55
        }
56 4
    }
57
}
58