Lines
87.50%
7 / 8
Functions and Methods
0.00%
0 / 1
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Profiler | 87.50% | 7 / 8 | 0.00% | 0 / 1 | 3.02 | 0.00% | 0 / 1 | |||
| __invoke | 87.50% | 7 / 8 | 0.00% | 0 / 1 | 3.02 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | namespace BO\Slim\Middleware; | |
| 4 | ||
| 5 | use Psr\Http\Message\ServerRequestInterface; | |
| 6 | use Psr\Http\Message\ResponseInterface; | |
| 7 | use Psr\Http\Server\RequestHandlerInterface; | |
| 8 | use BO\Slim\Factory\ResponseFactory; | |
| 9 | ||
| 10 | class Profiler | |
| 11 | { | |
| 12 | /** | |
| 13 | * | |
| 14 | */ | |
| 15 | public function __invoke(ServerRequestInterface $request, ?RequestHandlerInterface $next): ResponseInterface | |
| 16 | { | |
| 17 | \BO\Slim\Profiler::add("Routing"); | |
| 18 | if (null !== $next) { | |
| 19 | $response = $next->handle($request); | |
| 20 | } else { | |
| 21 | $response = (new ResponseFactory())->createResponse(); | |
| 22 | } | |
| 23 | ||
| 24 | /** @psalm-suppress TypeDoesNotContainType Module App subclasses may set DEBUG to true. */ | |
| 25 | if (\App::DEBUG) { | |
| 26 | \BO\Slim\Profiler::addMemoryPeak(); | |
| 27 | $response = $response->withAddedHeader('X-Profiling', \BO\Slim\Profiler::getList()); | |
| 28 | } | |
| 29 | ||
| 30 | return $response; | |
| 31 | } | |
| 32 | } |