HeadersAnnotHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

1 Method

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