Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
87.50% covered (warning)
87.50%
7 / 8
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
Profiler
87.50% covered (warning)
87.50%
7 / 8
0.00% covered (danger)
0.00%
0 / 1
3.02
0.00% covered (danger)
0.00%
0 / 1
 __invoke
87.50% covered (warning)
87.50%
7 / 8
0.00% covered (danger)
0.00%
0 / 1
3.02
1<?php
2
3namespace BO\Slim\Middleware;
4
5use Psr\Http\Message\ServerRequestInterface;
6use Psr\Http\Message\ResponseInterface;
7use Psr\Http\Server\RequestHandlerInterface;
8use BO\Slim\Factory\ResponseFactory;
9
10class 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}