PartParamHandler::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 Tebru\Retrofit\Internal\RequestBuilder;
12
use Tebru\Retrofit\RequestBodyConverter;
13
14
/**
15
 * Class PartParamHandler
16
 *
17
 * @author Nate Brunette <[email protected]>
18
 */
19 View Code Duplication
final class PartParamHandler extends AbstractParameterHandler
20
{
21
    /**
22
     * @var RequestBodyConverter
23
     */
24
    private $converter;
25
26
    /**
27
     * @var string
28
     */
29
    private $name;
30
31
    /**
32
     * @var string
33
     */
34
    private $encoding;
35
36
    /**
37
     * Constructor
38
     *
39
     * @param RequestBodyConverter $converter
40
     * @param string $name
41
     * @param string $encoding
42
     */
43 7
    public function __construct(RequestBodyConverter $converter, string $name, string $encoding)
44
    {
45 7
        $this->converter = $converter;
46 7
        $this->name = $name;
47 7
        $this->encoding = $encoding;
48 7
    }
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
     */
57 5
    public function apply(RequestBuilder $requestBuilder, $value): void
58
    {
59 5
        if ($value === null) {
60 1
            return;
61
        }
62
63 4
        $this->handlePart($requestBuilder, $this->converter, $this->name, $value, $this->encoding);
64 4
    }
65
}
66