Passed
Branch master (203e41)
by Nate
01:56
created

BodyAnnotHandler   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 2
dl 0
loc 21
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 9 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\AnnotationHandler;
10
11
use Tebru\AnnotationReader\AbstractAnnotation;
12
use Tebru\Retrofit\AnnotationHandler;
13
use Tebru\Retrofit\Converter;
14
use Tebru\Retrofit\Internal\ParameterHandler\BodyParamHandler;
15
use Tebru\Retrofit\RequestBodyConverter;
16
use Tebru\Retrofit\ServiceMethodBuilder;
17
18
/**
19
 * Class BodyAnnotHandler
20
 *
21
 * @author Nate Brunette <[email protected]>
22
 */
23
final class BodyAnnotHandler implements AnnotationHandler
24
{
25
    /**
26
     * Sets the request method as 'json' and adds a parameter handler for body json data
27
     *
28
     * @param AbstractAnnotation $annotation The annotation to handle
29
     * @param ServiceMethodBuilder $serviceMethodBuilder Used to construct a [@see ServiceMethod]
30
     * @param Converter|RequestBodyConverter $converter Converter used to convert types before sending to service method
31
     * @param int|null $index The position of the parameter or null if annotation does not reference parameter
32
     * @return void
33
     */
34 4
    public function handle(
35
        AbstractAnnotation $annotation,
36
        ServiceMethodBuilder $serviceMethodBuilder,
37
        ?Converter $converter,
38
        ?int $index
39
    ): void {
40 4
        $serviceMethodBuilder->setIsJson();
41 3
        $serviceMethodBuilder->addParameterHandler($index, new BodyParamHandler($converter));
0 ignored issues
show
Compatibility introduced by
$converter of type object<Tebru\Retrofit\Converter> is not a sub-type of object<Tebru\Retrofit\RequestBodyConverter>. It seems like you assume a child interface of the interface Tebru\Retrofit\Converter to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
42 3
    }
43
}
44