Code Duplication    Length = 27-29 lines in 3 locations

src/HeaderDefaultsPlugin.php 1 location

@@ 17-45 (lines=29) @@
14
 *
15
 * @deprecated since since version 1.1, and will be removed in 2.0. Use {@link \Http\Client\Common\Plugin\HeaderDefaultsPlugin} instead.
16
 */
17
class HeaderDefaultsPlugin implements Plugin
18
{
19
    private $headers = [];
20
21
    /**
22
     * @param array $headers headers to set to the request
23
     */
24
    public function __construct(array $headers)
25
    {
26
        $this->headers = $headers;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function handleRequest(RequestInterface $request, callable $next, callable $first)
33
    {
34
        foreach ($this->headers as $header => $headerValue) {
35
            if (!$request->hasHeader($header)) {
36
                $request = $request->withHeader($header, $headerValue);
37
            }
38
        }
39
40
        return $next($request);
41
    }
42
}
43

src/HeaderRemovePlugin.php 1 location

@@ 16-42 (lines=27) @@
13
 *
14
 * @deprecated since since version 1.1, and will be removed in 2.0. Use {@link \Http\Client\Common\Plugin\HeaderRemovePlugin} instead.
15
 */
16
class HeaderRemovePlugin implements Plugin
17
{
18
    private $headers = [];
19
20
    /**
21
     * @param array $headers headers 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/HeaderSetPlugin.php 1 location

@@ 17-43 (lines=27) @@
14
 *
15
 * @deprecated since since version 1.1, and will be removed in 2.0. Use {@link \Http\Client\Common\Plugin\HeaderSetPlugin} instead.
16
 */
17
class HeaderSetPlugin implements Plugin
18
{
19
    private $headers = [];
20
21
    /**
22
     * @param array $headers headers to set to the request
23
     */
24
    public function __construct(array $headers)
25
    {
26
        $this->headers = $headers;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function handleRequest(RequestInterface $request, callable $next, callable $first)
33
    {
34
        foreach ($this->headers as $header => $headerValue) {
35
            $request = $request->withHeader($header, $headerValue);
36
        }
37
38
        return $next($request);
39
    }
40
}
41