Completed
Pull Request — master (#44)
by
unknown
12:15
created

HeaderAppendPlugin   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 27
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handleRequest() 0 9 2
1
<?php
2
3
namespace Http\Client\Plugin;
4
5
use Psr\Http\Message\RequestInterface;
6
7
/**
8
 * Adds headers to the request.
9
 * If the header already exists the value will be appended to the current value
10
 */
11
class HeaderAppendPlugin implements Plugin
12
{
13
14
    private $headers = [];
15
16
    /**
17
     * @param array $headers headers to add to the request
18
     */
19 3
    public function __construct(array $headers)
20
    {
21 3
        $this->headers = $headers;
22 3
    }
23
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 1
    public function handleRequest(RequestInterface $request, callable $next, callable $first)
29
    {
30 1
        foreach ($this->headers as $header => $headerValue) {
31 1
            $request = $request->withAddedHeader($header, $headerValue);
32 1
        }
33
34
35 1
        return $next($request);
36
    }
37
}
38