Code Duplication    Length = 27-29 lines in 3 locations

src/Plugin/HeaderRemovePlugin.php 1 location

@@ 13-41 (lines=29) @@
10
 *
11
 * @author Soufiane Ghzal <[email protected]>
12
 */
13
final class HeaderRemovePlugin implements Plugin
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
    public function __construct(array $headers)
24
    {
25
        $this->headers = $headers;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function handleRequest(RequestInterface $request, callable $next, callable $first)
32
    {
33
        foreach ($this->headers as $header) {
34
            if ($request->hasHeader($header)) {
35
                $request = $request->withoutHeader($header);
36
            }
37
        }
38
39
        return $next($request);
40
    }
41
}
42

src/Plugin/HeaderDefaultsPlugin.php 1 location

@@ 15-43 (lines=29) @@
12
 *
13
 * @author Soufiane Ghzal <[email protected]>
14
 */
15
final class HeaderDefaultsPlugin implements Plugin
16
{
17
    /**
18
     * @var array
19
     */
20
    private $headers = [];
21
22
    /**
23
     * @param array $headers Hashmap of header name to header value
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 => $headerValue) {
36
            if (!$request->hasHeader($header)) {
37
                $request = $request->withHeader($header, $headerValue);
38
            }
39
        }
40
41
        return $next($request);
42
    }
43
}
44

src/Plugin/HeaderSetPlugin.php 1 location

@@ 15-41 (lines=27) @@
12
 *
13
 * @author Soufiane Ghzal <[email protected]>
14
 */
15
final class HeaderSetPlugin implements Plugin
16
{
17
    /**
18
     * @var array
19
     */
20
    private $headers = [];
21
22
    /**
23
     * @param array $headers Hashmap of header name to header value
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 => $headerValue) {
36
            $request = $request->withHeader($header, $headerValue);
37
        }
38
39
        return $next($request);
40
    }
41
}
42