UrlParamHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
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 34
loc 34
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A apply() 8 8 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 RuntimeException;
12
use Tebru\Retrofit\Internal\RequestBuilder;
13
use Tebru\Retrofit\StringConverter;
14
15
/**
16
 * Class UrlParamHandler
17
 *
18
 * @author Nate Brunette <[email protected]>
19
 */
20 View Code Duplication
final class UrlParamHandler extends AbstractParameterHandler
21
{
22
    /**
23
     * @var StringConverter
24
     */
25
    private $converter;
26
27
    /**
28
     * Constructor
29
     *
30
     * @param StringConverter $converter
31
     */
32 4
    public function __construct(StringConverter $converter)
33
    {
34 4
        $this->converter = $converter;
35 4
    }
36
37
    /**
38
     * Set a value to the [@see RequestBuilder] for parameter type
39
     *
40
     * @param RequestBuilder $requestBuilder
41
     * @param mixed $value
42
     * @return void
43
     * @throws \RuntimeException
44
     */
45 3
    public function apply(RequestBuilder $requestBuilder, $value): void
46
    {
47 3
        if ($value === null) {
48 1
            throw new RuntimeException('Url parameters cannot be null');
49
        }
50
51 2
        $requestBuilder->setBaseUrl($this->converter->convert($value));
52 2
    }
53
}
54