UrlParamHandler::apply()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
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