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

HeaderMapParamHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A apply() 0 8 3
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 HeaderMapParamHandler
17
 *
18
 * @author Nate Brunette <[email protected]>
19
 */
20
final class HeaderMapParamHandler extends AbstractParameterHandler
21
{
22
    /**
23
     * @var StringConverter
24
     */
25
    private $converter;
26
27
    /**
28
     * Constructor
29
     *
30
     * @param StringConverter $converter
31
     */
32
    public function __construct(StringConverter $converter)
33
    {
34
        $this->converter = $converter;
35
    }
36
37
    /**
38
     * Set a value to the [@see RequestBuilder] for parameter type
39
     *
40
     * @param RequestBuilder $requestBuilder
41
     * @param array|Iterator $map
42
     * @return void
43
     * @throws \RuntimeException
44
     */
45
    public function apply(RequestBuilder $requestBuilder, $map): void
46
    {
47
        foreach ($map as $name => $value) {
48
            foreach ($this->getListValues($value) as $element) {
49
                $requestBuilder->addHeader($name, $this->converter->convert($element));
50
            }
51
        }
52
    }
53
}
54