Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
4 / 4 |
|
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ViewHandler | |
100.00% |
5 / 5 |
|
100.00% |
4 / 4 |
|
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| handle | |
100.00% |
4 / 4 |
|
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celemas\Router; |
| 6 | |
| 7 | use Override; |
| 8 | use Psr\Http\Message\ResponseInterface as Response; |
| 9 | use Psr\Http\Message\ServerRequestInterface as Request; |
| 10 | use Psr\Http\Server\MiddlewareInterface as Middleware; |
| 11 | use Psr\Http\Server\RequestHandlerInterface as RequestHandler; |
| 12 | |
| 13 | /** @internal */ |
| 14 | final class ViewHandler implements RequestHandler |
| 15 | { |
| 16 | /** @var list<Middleware> */ |
| 17 | protected array $middleware; |
| 18 | |
| 19 | /** @param list<Middleware> $globalMiddleware */ |
| 20 | public function __construct( |
| 21 | protected readonly View $view, |
| 22 | array $globalMiddleware, |
| 23 | ) { |
| 24 | $this->middleware = array_merge($globalMiddleware, $view->middleware()); |
| 25 | } |
| 26 | |
| 27 | #[Override] |
| 28 | public function handle(Request $request): Response |
| 29 | { |
| 30 | if (0 === count($this->middleware)) { |
| 31 | return $this->view->execute($request); |
| 32 | } |
| 33 | |
| 34 | $middleware = array_shift($this->middleware); |
| 35 | assert( |
| 36 | $middleware instanceof Middleware, |
| 37 | 'Expected middleware stack item to implement Middleware.', |
| 38 | ); |
| 39 | |
| 40 | return $middleware->process($request, $this); |
| 41 | } |
| 42 | } |
Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not
necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once.
Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 21 | protected readonly View $view, |
| 22 | array $globalMiddleware, |
| 23 | ) { |
| 24 | $this->middleware = array_merge($globalMiddleware, $view->middleware()); |
| 25 | } |
| 28 | public function handle(Request $request): Response |
| 29 | { |
| 30 | if (0 === count($this->middleware)) { |
| 31 | return $this->view->execute($request); |
| 34 | $middleware = array_shift($this->middleware); |
| 35 | assert( |
| 36 | $middleware instanceof Middleware, |
| 37 | 'Expected middleware stack item to implement Middleware.', |
| 38 | ); |
| 39 | |
| 40 | return $middleware->process($request, $this); |
| 41 | } |