FieldMapParamHandler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 44
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A apply() 0 12 4
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 FieldMapParamHandler
17
 *
18
 * @author Nate Brunette <[email protected]>
19
 */
20
final class FieldMapParamHandler extends AbstractParameterHandler
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 7
    public function __construct(StringConverter $converter, bool $encoded)
39
    {
40 7
        $this->converter = $converter;
41 7
        $this->encoded = $encoded;
42 7
    }
43
44
    /**
45
     * Set a value to the [@see RequestBuilder] for parameter type
46
     *
47
     * @param RequestBuilder $requestBuilder
48
     * @param array|Iterator $map
49
     * @throws \RuntimeException
50
     */
51 6
    public function apply(RequestBuilder $requestBuilder, $map): void
52
    {
53 6
        if ($map === null) {
54 1
            return;
55
        }
56
57 5
        foreach ($map as $name => $value) {
58 4
            foreach ($this->getListValues($value) as $element) {
59 3
                $requestBuilder->addField($name, $this->converter->convert($element), $this->encoded);
60
            }
61
        }
62 4
    }
63
}
64