PartMapParamHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 42
loc 42
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A apply() 10 10 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\RequestBodyConverter;
14
15
/**
16
 * Class PartMapParamHandler
17
 *
18
 * @author Nate Brunette <[email protected]>
19
 */
20 View Code Duplication
final class PartMapParamHandler extends AbstractParameterHandler
21
{
22
    /**
23
     * @var RequestBodyConverter
24
     */
25
    private $converter;
26
27
    /**
28
     * @var string
29
     */
30
    private $encoding;
31
32
    /**
33
     * Constructor
34
     *
35
     * @param RequestBodyConverter $converter
36
     * @param string $encoding
37
     */
38 6
    public function __construct(RequestBodyConverter $converter, string $encoding)
39
    {
40 6
        $this->converter = $converter;
41 6
        $this->encoding = $encoding;
42 6
    }
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
     */
51 5
    public function apply(RequestBuilder $requestBuilder, $map): void
52
    {
53 5
        if ($map === null) {
54 1
            return;
55
        }
56
57 4
        foreach ($map as $name => $value) {
58 3
            $this->handlePart($requestBuilder, $this->converter, $name, $value, $this->encoding);
59
        }
60 4
    }
61
}
62