Code Duplication    Length = 27-29 lines in 3 locations

src/Plugin/HeaderDefaultsPlugin.php 1 location

@@ 16-44 (lines=29) @@
13
 *
14
 * TODO: make class final in version 2.0, once plugins does not extend it anymore.
15
 */
16
/*final*/ class HeaderDefaultsPlugin implements Plugin
17
{
18
    /**
19
     * @var array
20
     */
21
    private $headers = [];
22
23
    /**
24
     * @param array $headers headers to set to the request
25
     */
26
    public function __construct(array $headers)
27
    {
28
        $this->headers = $headers;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function handleRequest(RequestInterface $request, callable $next, callable $first)
35
    {
36
        foreach ($this->headers as $header => $headerValue) {
37
            if (!$request->hasHeader($header)) {
38
                $request = $request->withHeader($header, $headerValue);
39
            }
40
        }
41
42
        return $next($request);
43
    }
44
}
45

src/Plugin/HeaderRemovePlugin.php 1 location

@@ 15-43 (lines=29) @@
12
 *
13
 * TODO: make class final in version 2.0, once plugins does not extend it anymore.
14
 */
15
/*final*/ class HeaderRemovePlugin implements Plugin
16
{
17
    /**
18
     * @var array
19
     */
20
    private $headers = [];
21
22
    /**
23
     * @param array $headers headers to remove from the request
24
     */
25
    public function __construct(array $headers)
26
    {
27
        $this->headers = $headers;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function handleRequest(RequestInterface $request, callable $next, callable $first)
34
    {
35
        foreach ($this->headers as $header) {
36
            if ($request->hasHeader($header)) {
37
                $request = $request->withoutHeader($header);
38
            }
39
        }
40
41
        return $next($request);
42
    }
43
}
44

src/Plugin/HeaderSetPlugin.php 1 location

@@ 16-42 (lines=27) @@
13
 *
14
 * TODO: make class final in version 2.0, once plugins does not extend it anymore.
15
 */
16
/*final*/ class HeaderSetPlugin implements Plugin
17
{
18
    /**
19
     * @var array
20
     */
21
    private $headers = [];
22
23
    /**
24
     * @param array $headers headers to set to the request
25
     */
26
    public function __construct(array $headers)
27
    {
28
        $this->headers = $headers;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function handleRequest(RequestInterface $request, callable $next, callable $first)
35
    {
36
        foreach ($this->headers as $header => $headerValue) {
37
            $request = $request->withHeader($header, $headerValue);
38
        }
39
40
        return $next($request);
41
    }
42
}
43