Conditions | 4 |
Paths | 4 |
Total Lines | 34 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Tests | 17 |
CRAP Score | 4.0027 |
Changes | 0 |
1 | <?php |
||
14 | 8 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
15 | { |
||
16 | 8 | $response = $handler->handle($request); |
|
17 | |||
18 | 8 | if (!$this->containsHtml($response)) { |
|
19 | 2 | return $response; |
|
20 | } |
||
21 | |||
22 | 6 | $htmlOriginal = $response->getBody()->getContents(); |
|
23 | |||
24 | 6 | if (0 === strlen($htmlOriginal)) { |
|
25 | 2 | return $response; |
|
26 | } |
||
27 | |||
28 | 4 | $minifier = tidy_parse_string($htmlOriginal, $this->getConfig(), 'utf8'); |
|
29 | 4 | assert($minifier instanceof tidy); |
|
30 | |||
31 | 4 | if (!tidy_clean_repair($minifier)) { |
|
32 | return $response; |
||
33 | } |
||
34 | |||
35 | // @phpstan-ignore-next-line |
||
36 | 4 | $htmlModified = (string) $minifier->html(); |
|
37 | 4 | $htmlModified = trim($htmlModified); |
|
38 | |||
39 | 4 | [$in, $out, $diff] = $this->getSuffixStatistics($htmlOriginal, $htmlModified); |
|
40 | |||
41 | 4 | $htmlModified .= PHP_EOL . sprintf(self::SUFFIX, $in, $out, $diff); |
|
42 | |||
43 | 4 | unset($minifier, $htmlOriginal); |
|
44 | |||
45 | 4 | $body = Factory::getStreamFactory()->createStream($htmlModified); |
|
46 | |||
47 | 4 | return $response->withBody($body); |
|
48 | } |
||
50 |