Passed
Branch master (203e41)
by Nate
02:00
created

QueryParamHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 46
loc 46
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A apply() 6 6 2

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 Tebru\Retrofit\Internal\RequestBuilder;
12
use Tebru\Retrofit\StringConverter;
13
14
/**
15
 * Class QueryParamHandler
16
 *
17
 * @author Nate Brunette <[email protected]>
18
 */
19 View Code Duplication
final class QueryParamHandler 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...
20
{
21
    /**
22
     * @var StringConverter
23
     */
24
    private $converter;
25
26
    /**
27
     * @var string
28
     */
29
    private $name;
30
31
    /**
32
     * @var bool
33
     */
34
    private $encoded;
35
36
    /**
37
     * Constructor
38
     *
39
     * @param string $name
40
     * @param StringConverter $converter
41
     * @param bool $encoded
42
     */
43 6
    public function __construct(StringConverter $converter, string $name, bool $encoded)
44
    {
45 6
        $this->converter = $converter;
46 6
        $this->name = $name;
47 6
        $this->encoded = $encoded;
48 6
    }
49
50
    /**
51
     * Set a value to the [@see RequestBuilder] for parameter type
52
     *
53
     * @param RequestBuilder $requestBuilder
54
     * @param mixed $value
55
     * @return void
56
     * @throws \RuntimeException
57
     */
58 4
    public function apply(RequestBuilder $requestBuilder, $value): void
59
    {
60 4
        foreach ($this->getListValues($value) as $element) {
61 3
            $requestBuilder->addQuery($this->name, $this->converter->convert($element), $this->encoded);
62
        }
63 4
    }
64
}
65