| Total Complexity | 5 |
| Total Lines | 43 |
| Duplicated Lines | 0 % |
| Coverage | 84.62% |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | final class MiddlewareStack implements JsonRpc\Procedure |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var JsonRpc\Middleware |
||
| 14 | */ |
||
| 15 | private $middleware; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var JsonRpc\Procedure |
||
| 19 | */ |
||
| 20 | private $next; |
||
| 21 | |||
| 22 | 13 | public static function compose(JsonRpc\Procedure $bottom, JsonRpc\Middleware ...$middlewares): JsonRpc\Procedure |
|
| 23 | { |
||
| 24 | 13 | $stack = $bottom; |
|
| 25 | |||
| 26 | 13 | foreach ($middlewares as $middleware) { |
|
| 27 | 1 | $stack = new self($middleware, $stack); |
|
| 28 | } |
||
| 29 | |||
| 30 | 13 | return $stack; |
|
| 31 | } |
||
| 32 | |||
| 33 | 1 | private function __construct(JsonRpc\Middleware $middleware, JsonRpc\Procedure $next) |
|
| 34 | { |
||
| 35 | 1 | $this->middleware = $middleware; |
|
| 36 | 1 | $this->next = $next; |
|
| 37 | 1 | } |
|
| 38 | |||
| 39 | /** |
||
| 40 | * {@inheritdoc} |
||
| 41 | */ |
||
| 42 | 1 | public function execute(JsonRpc\Request $request): JsonRpc\Response |
|
| 43 | { |
||
| 44 | 1 | return $this->middleware->process($request, $this->next); |
|
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * {@inheritdoc} |
||
| 49 | */ |
||
| 50 | public function getSpec(): ?stdClass |
||
| 53 | } |
||
| 54 | } |
||
| 55 |