Completed
Pull Request — master (#72)
by Nate
03:35
created

HeadersAnnotHandler::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 4
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\ServiceMethodBuilder;
15
16
/**
17
 * Class HeadersAnnotHandler
18
 *
19
 * @author Nate Brunette <[email protected]>
20
 */
21
final class HeadersAnnotHandler implements AnnotationHandler
22
{
23
    /**
24
     * Set each header to request
25
     *
26
     * @param AbstractAnnotation $annotation The annotation to handle
27
     * @param ServiceMethodBuilder $serviceMethodBuilder Used to construct a [@see ServiceMethod]
28
     * @param Converter|null $converter Converter used to convert types before sending to service method
29
     * @param int|null $index The position of the parameter or null if annotation does not reference parameter
30
     * @return void
31
     */
32
    public function handle(
33
        AbstractAnnotation $annotation,
34
        ServiceMethodBuilder $serviceMethodBuilder,
35
        ?Converter $converter,
36
        ?int $index
37
    ): void {
38
        /** @var string[] $headerList */
39
        $headerList = $annotation->getValue();
40
        foreach ($headerList as $name => $header) {
41
            $serviceMethodBuilder->addHeader($name, $header);
42
        }
43
    }
44
}
45