Passed
Push — master ( 052230...fc0db7 )
by Arnold
09:03
created

ClientMiddleware   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 41
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ handleRequest() 0 3 1
A hp$0 ➔ forHttplug() 0 6 1
A forGuzzle() 0 5 1
forHttplug() 0 6 ?
A asDoublePass() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace Jasny\Dummy;
4
5
use Http\Client\Common\Plugin as HttpPlugin;
6
use Http\Promise\Promise as HttpPromise;
7
use Psr\Http\Message\RequestInterface;
8
use Psr\Http\Message\ResponseInterface;
9
10
/**
11
 * Dummy middleware for PSR-7 HTTP clients.
12
 */
13
class ClientMiddleware
14
{
15
    /**
16
     * Return a callback that can be used as double pass middleware.
17
     *
18
     * @return callable
19
     */
20 1
    public function asDoublePass(): callable
21
    {
22
        return function (RequestInterface $request, ResponseInterface $response, callable $next): ResponseInterface {
23 1
            return $next($request, $response);
24 1
        };
25
    }
26
27
    /**
28
     * Return a callback that can be used as Guzzle middleware.
29
     * @see http://docs.guzzlephp.org/en/stable/handlers-and-middleware.html
30
     *
31
     * @return callable
32
     */
33 2
    public function forGuzzle(): callable
34
    {
35
        return function (callable $handler) {
36
            return function (RequestInterface $request, array $options) use ($handler) {
37 2
                return $handler($request, $options);
38 2
            };
39 2
        };
40
    }
41
42
    /**
43
     * Create a version of this middleware that can be used in HTTPlug.
44
     * @see http://docs.php-http.org/en/latest/plugins/introduction.html
45
     *
46
     * @return self&HttpPlugin
0 ignored issues
show
Documentation Bug introduced by
The doc comment self&HttpPlugin at position 0 could not be parsed: 'self' is only available from within classes.
Loading history...
47
     */
48
    public function forHttplug(): HttpPlugin
49
    {
50
        return new class () extends ClientMiddleware implements HttpPlugin {
51 1
            public function handleRequest(RequestInterface $request, callable $next, callable $first): HttpPromise
52
            {
53 1
                return $next($request);
54
            }
55
        };
56
    }
57
}
58