HeaderAppendPlugin   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 24
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handleRequest() 0 8 2
1
<?php
2
3
namespace Http\Client\Plugin;
4
5 1
@trigger_error('The '.__NAMESPACE__.'\HeaderAppendPlugin class is deprecated since version 1.1 and will be removed in 2.0. Use Http\Client\Common\Plugin\HeaderAppendPlugin instead.', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
6
7
use Psr\Http\Message\RequestInterface;
8
9
/**
10
 * Adds headers to the request.
11
 * If the header already exists the value will be appended to the current value.
12
 *
13
 * This only makes sense for headers that can have multiple values like 'Forwarded'
14
 *
15
 * @see https://en.wikipedia.org/wiki/List_of_HTTP_header_fields
16
 *
17
 * @author Soufiane Ghzal <[email protected]>
18
 *
19
 * @deprecated since since version 1.1, and will be removed in 2.0. Use {@link \Http\Client\Common\Plugin\HeaderAppendPlugin} instead.
20
 */
21
class HeaderAppendPlugin implements Plugin
0 ignored issues
show
Deprecated Code introduced by
The interface Http\Client\Plugin\Plugin has been deprecated with message: since since version 1.1, and will be removed in 2.0. Use {@link \Http\Client\Common\Plugin} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
22
{
23
    private $headers = [];
24
25
    /**
26
     * @param array $headers headers to add to the request
27
     */
28 3
    public function __construct(array $headers)
29
    {
30 3
        $this->headers = $headers;
31 3
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 1
    public function handleRequest(RequestInterface $request, callable $next, callable $first)
37
    {
38 1
        foreach ($this->headers as $header => $headerValue) {
39 1
            $request = $request->withAddedHeader($header, $headerValue);
40 1
        }
41
42 1
        return $next($request);
43
    }
44
}
45