HeaderAnnotHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 31
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 18 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\AnnotationHandler;
10
11
use InvalidArgumentException;
12
use Tebru\AnnotationReader\AbstractAnnotation;
13
use Tebru\Retrofit\AnnotationHandler;
14
use Tebru\Retrofit\Converter;
15
use Tebru\Retrofit\Internal\ParameterHandler\HeaderParamHandler;
16
use Tebru\Retrofit\ServiceMethodBuilder;
17
use Tebru\Retrofit\StringConverter;
18
19
/**
20
 * Class HeaderAnnotHandler
21
 *
22
 * @author Nate Brunette <[email protected]>
23
 */
24
final class HeaderAnnotHandler implements AnnotationHandler
25
{
26
    /**
27
     * Adds header param handler
28
     *
29
     * @param AbstractAnnotation $annotation The annotation to handle
30
     * @param ServiceMethodBuilder $serviceMethodBuilder Used to construct a [@see ServiceMethod]
31
     * @param Converter|StringConverter $converter Converter used to convert types before sending to service method
32
     * @param int|null $index The position of the parameter or null if annotation does not reference parameter
33
     * @return void
34
     * @throws \InvalidArgumentException
35
     */
36 3
    public function handle(
37
        AbstractAnnotation $annotation,
38
        ServiceMethodBuilder $serviceMethodBuilder,
39
        ?Converter $converter,
40
        ?int $index
41
    ): void {
42 3
        if (!$converter instanceof StringConverter) {
43 1
            throw new InvalidArgumentException(sprintf(
44 1
                'Retrofit: Converter must be a StringConverter, %s found',
45 1
                \gettype($converter)
46
            ));
47
        }
48
49 2
        $serviceMethodBuilder->addParameterHandler(
50 2
            $index,
51 2
            new HeaderParamHandler($converter, $annotation->getValue())
52
        );
53 2
    }
54
}
55