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

BodyParamHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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 Tebru\Retrofit\Internal\RequestBuilder;
12
use Tebru\Retrofit\RequestBodyConverter;
13
14
/**
15
 * Class BodyParamHandler
16
 *
17
 * @author Nate Brunette <[email protected]>
18
 */
19 View Code Duplication
final class BodyParamHandler 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 RequestBodyConverter
23
     */
24
    private $converter;
25
26
    /**
27
     * Constructor
28
     *
29
     * @param RequestBodyConverter $converter
30
     */
31 11
    public function __construct(RequestBodyConverter $converter)
32
    {
33 11
        $this->converter = $converter;
34 11
    }
35
36
    /**
37
     * Converts the value to a stream, then sets the body to the request builder
38
     *
39
     * @param RequestBuilder $requestBuilder
40
     * @param mixed $value
41
     * @return void
42
     */
43 4
    public function apply(RequestBuilder $requestBuilder, $value): void
44
    {
45 4
        if ($value === null) {
46 1
            return;
47
        }
48
49 3
        $requestBuilder->setBody($this->converter->convert($value));
50 3
    }
51
}
52