| Conditions | 1 |
| Paths | 1 |
| Total Lines | 17 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | public function minify(string $htmlSource): string |
||
| 11 | { |
||
| 12 | $lut = [ |
||
| 13 | '/(\n|^)(\x20+|\t)/' => "\n", |
||
| 14 | '/(\n|^)\/\/(.*?)(\n|$)/' => "\n", |
||
| 15 | '/\n/' => ' ', |
||
| 16 | '/\<\!--.*?-->/' => '', |
||
| 17 | '/(\x20+|\t)/' => ' ', // Delete multi space (Without \n) |
||
| 18 | '/\>\s+\</' => '> <', // Replace white spaces between tags with one space |
||
| 19 | '/(\"|\')\s+\>/' => '$1>', // Strip whitespaces between quotation ("') and end tags |
||
| 20 | '/=\s+(\"|\')/' => '=$1', // Strip whitespaces between = "' |
||
| 21 | ]; |
||
| 22 | |||
| 23 | $htmlMinified = preg_replace(array_keys($lut), array_values($lut), $htmlSource); |
||
| 24 | assert(is_string($htmlMinified)); |
||
| 25 | |||
| 26 | return $this->postProcess($htmlMinified); |
||
| 27 | } |
||
| 29 |