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

HeaderSetPlugin   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 100 %

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 24
loc 24
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A handleRequest() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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