These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 | View Code Duplication | final class HeaderRemovePlugin implements Plugin |
|
0 ignored issues
–
show
|
|||
14 | { |
||
15 | /** |
||
16 | * @var array |
||
17 | */ |
||
18 | private $headers = []; |
||
19 | |||
20 | /** |
||
21 | * @param array $headers List of header names to remove from the request |
||
22 | */ |
||
23 | 3 | public function __construct(array $headers) |
|
24 | { |
||
25 | 3 | $this->headers = $headers; |
|
26 | 3 | } |
|
27 | |||
28 | /** |
||
29 | * {@inheritdoc} |
||
30 | */ |
||
31 | 1 | public function handleRequest(RequestInterface $request, callable $next, callable $first) |
|
32 | { |
||
33 | 1 | foreach ($this->headers as $header) { |
|
34 | 1 | if ($request->hasHeader($header)) { |
|
35 | 1 | $request = $request->withoutHeader($header); |
|
36 | } |
||
37 | } |
||
38 | |||
39 | 1 | return $next($request); |
|
40 | } |
||
41 | } |
||
42 |
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.