Completed
Pull Request — master (#14)
by Márk
05:00
created

HeaderRemovePlugin::__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 1
Metric Value
c 1
b 0
f 1
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\Common\Plugin;
4
5
use Http\Client\Common\Plugin;
6
use Psr\Http\Message\RequestInterface;
7
8
/**
9
 * Removes headers from the request.
10
 *
11
 * @author Soufiane Ghzal <[email protected]>
12
 *
13
 * TODO: make class final in version 2.0, once plugins does not extend it anymore.
14
 */
15 View Code Duplication
/*final*/ class HeaderRemovePlugin 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...
16
{
17
    /**
18
     * @var array
19
     */
20
    private $headers = [];
21
22
    /**
23
     * @param array $headers headers to remove from the request
24
     */
25 3
    public function __construct(array $headers)
26
    {
27 3
        $this->headers = $headers;
28 3
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 1
    public function handleRequest(RequestInterface $request, callable $next, callable $first)
34
    {
35 1
        foreach ($this->headers as $header) {
36 1
            if ($request->hasHeader($header)) {
37 1
                $request = $request->withoutHeader($header);
38 1
            }
39 1
        }
40
41 1
        return $next($request);
42
    }
43
}
44