abordage /
laravel-html-min
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Abordage\LaravelHtmlMin\Middleware; |
||
| 6 | |||
| 7 | use Abordage\LaravelHtmlMin\Facades\HtmlMin; |
||
| 8 | use Closure; |
||
| 9 | use Illuminate\Http\Request; |
||
| 10 | use Illuminate\Http\Response; |
||
| 11 | |||
| 12 | class HtmlMinify |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @param Request $request |
||
| 16 | * @param Closure $next |
||
| 17 | * @return Response|mixed |
||
| 18 | */ |
||
| 19 | public function handle(Request $request, Closure $next) |
||
| 20 | { |
||
| 21 | $response = $next($request); |
||
| 22 | |||
| 23 | if (!$this->compressionPossible($request, $response)) { |
||
| 24 | return $response; |
||
| 25 | } |
||
| 26 | |||
| 27 | $html = $response->getContent(); |
||
| 28 | |||
| 29 | if (class_exists('\BeyondCode\ServerTiming\Facades\ServerTiming')) { |
||
| 30 | \BeyondCode\ServerTiming\Facades\ServerTiming::start('Minification'); |
||
|
0 ignored issues
–
show
|
|||
| 31 | } |
||
| 32 | |||
| 33 | $htmlMin = HtmlMin::minify($html); |
||
| 34 | |||
| 35 | if (class_exists('\BeyondCode\ServerTiming\Facades\ServerTiming')) { |
||
| 36 | \BeyondCode\ServerTiming\Facades\ServerTiming::stop('Minification'); |
||
| 37 | } |
||
| 38 | |||
| 39 | return $response->setContent($htmlMin); |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param Request $request |
||
| 44 | * @param mixed $response |
||
| 45 | * @return bool |
||
| 46 | */ |
||
| 47 | private function compressionPossible(Request $request, $response): bool |
||
| 48 | { |
||
| 49 | if (!config('html-min.enable')) { |
||
| 50 | return false; |
||
| 51 | } |
||
| 52 | |||
| 53 | if (!in_array(strtoupper($request->getMethod()), ['GET', 'HEAD'])) { |
||
| 54 | return false; |
||
| 55 | } |
||
| 56 | |||
| 57 | if (!$response instanceof Response) { |
||
| 58 | return false; |
||
| 59 | } |
||
| 60 | |||
| 61 | if ($response->getStatusCode() >= 500) { |
||
| 62 | return false; |
||
| 63 | } |
||
| 64 | |||
| 65 | return true; |
||
| 66 | } |
||
| 67 | } |
||
| 68 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths