Completed
Pull Request — master (#72)
by Nate
03:35
created

QueryMapParamHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 5
Ratio 100 %

Importance

Changes 0
Metric Value
dl 5
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
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 Iterator;
12
use Tebru\Retrofit\Internal\RequestBuilder;
13
use Tebru\Retrofit\StringConverter;
14
15
/**
16
 * Class QueryMapParamHandler
17
 *
18
 * @author Nate Brunette <[email protected]>
19
 */
20 View Code Duplication
final class QueryMapParamHandler extends AbstractParameterHandler
1 ignored issue
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
{
22
    /**
23
     * @var StringConverter
24
     */
25
    private $converter;
26
27
    /**
28
     * @var bool
29
     */
30
    private $encoded;
31
32
    /**
33
     * Constructor
34
     *
35
     * @param StringConverter $converter
36
     * @param bool $encoded
37
     */
38
    public function __construct(StringConverter $converter, bool $encoded)
39
    {
40
        $this->converter = $converter;
41
        $this->encoded = $encoded;
42
    }
43
44
    /**
45
     * Set a value to the [@see RequestBuilder] for parameter type
46
     *
47
     * @param RequestBuilder $requestBuilder
48
     * @param array|Iterator $map
49
     * @return void
50
     * @throws \RuntimeException
51
     */
52
    public function apply(RequestBuilder $requestBuilder, $map): void
53
    {
54
        foreach ($map as $name => $value) {
55
            foreach ($this->getListValues($value) as $element) {
56
                $requestBuilder->addQuery($name, $this->converter->convert($element), $this->encoded);
57
            }
58
        }
59
    }
60
}
61