PathParamHandler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
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 PathParamHandler
17
 *
18
 * @author Nate Brunette <[email protected]>
19
 */
20
final class PathParamHandler extends AbstractParameterHandler
21
{
22
    /**
23
     * @var StringConverter
24
     */
25
    private $converter;
26
27
    /**
28
     * @var string
29
     */
30
    private $name;
31
32
    /**
33
     * Constructor
34
     *
35
     * @param StringConverter $converter
36
     * @param string $name
37
     */
38 4
    public function __construct(StringConverter $converter, string $name)
39
    {
40 4
        $this->converter = $converter;
41 4
        $this->name = $name;
42 4
    }
43
44
    /**
45
     * Set a value to the [@see RequestBuilder] for parameter type
46
     *
47
     * @param RequestBuilder $requestBuilder
48
     * @param mixed $value
49
     * @return void
50
     * @throws \RuntimeException
51
     */
52 3
    public function apply(RequestBuilder $requestBuilder, $value): void
53
    {
54 3
        if ($value === null) {
55 1
            throw new RuntimeException('Path parameters cannot be null');
56
        }
57
58 2
        $requestBuilder->replacePath($this->name, $this->converter->convert($value));
59 2
    }
60
}
61