Conditions | 7 |
Paths | 8 |
Total Lines | 34 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
17 | public function handle(Request $request, Closure $next) |
||
18 | { |
||
19 | $response = $next($request); |
||
20 | |||
21 | if (!config('html-min.enable')) { |
||
22 | return $response; |
||
23 | } |
||
24 | |||
25 | if (!in_array(strtoupper($request->getMethod()), ['GET', 'HEAD'])) { |
||
26 | return $response; |
||
27 | } |
||
28 | |||
29 | if (!$response instanceof Response) { |
||
30 | return $response; |
||
31 | } |
||
32 | |||
33 | if (!$response->getStatusCode() != 200) { |
||
34 | return $response; |
||
35 | } |
||
36 | |||
37 | $html = $response->getContent(); |
||
38 | |||
39 | if (class_exists('\BeyondCode\ServerTiming\Facades\ServerTiming')) { |
||
40 | \BeyondCode\ServerTiming\Facades\ServerTiming::start('Minification'); |
||
41 | } |
||
42 | |||
43 | /** @phpstan-ignore-next-line */ |
||
44 | $htmlMin = HtmlMin::minify($html); |
||
45 | |||
46 | if (class_exists('\BeyondCode\ServerTiming\Facades\ServerTiming')) { |
||
47 | \BeyondCode\ServerTiming\Facades\ServerTiming::stop('Minification'); |
||
48 | } |
||
49 | |||
50 | return $response->setContent($htmlMin); |
||
51 | } |
||
53 |