Completed
Pull Request — master (#14)
by Márk
03:42
created

HeaderRemovePlugin::handleRequest()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 10
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
cc 3
eloc 5
nc 3
nop 3
crap 3
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