Completed
Push — master ( 789cc6...743104 )
by David
53:58 queued 32:45
created

HeaderSetPlugin::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Http\Client\Plugin;
4
5
use Psr\Http\Message\RequestInterface;
6
7
/**
8
 * Set headers to the request.
9
 * If the header does not exist it wil be set, if the header already exists it will be replaced.
10
 *
11
 * @author Soufiane Ghzal <[email protected]>
12
 */
13 View Code Duplication
class HeaderSetPlugin implements Plugin
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    private $headers = [];
16
17
    /**
18
     * @param array $headers headers to set to the request
19
     */
20 3
    public function __construct(array $headers)
21
    {
22 3
        $this->headers = $headers;
23 3
    }
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->withHeader($header, $headerValue);
32 1
        }
33
34 1
        return $next($request);
35
    }
36
}
37