| Conditions | 4 |
| Paths | 4 |
| Total Lines | 34 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 22 |
| CRAP Score | 4 |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 33 | 2 | public function minify($src) |
|
| 34 | { |
||
| 35 | 2 | $content = $src; |
|
| 36 | 2 | $gzipHeaders = ''; |
|
| 37 | 2 | $url = $this->url; |
|
| 38 | 2 | if (extension_loaded('zlib')) |
|
| 39 | 2 | { |
|
| 40 | 2 | $content = gzencode($content, $this->gzLevel); |
|
| 41 | 2 | $gzipHeaders = "\r\nContent-encoding: gzip\r\nAccept-Encoding: gzip"; |
|
| 42 | 2 | $url = 'compress.zlib://' . $url; |
|
| 43 | 2 | } |
|
| 44 | |||
| 45 | $contextOptions = [ |
||
| 46 | 'http' => [ |
||
| 47 | 2 | 'method' => 'POST', |
|
| 48 | 'header' => "Connection: close\r\n" |
||
| 49 | . "Content-type: application/octet-stream\r\n" |
||
| 50 | 2 | . 'Content-length: ' . strlen($content) |
|
| 51 | 2 | . $gzipHeaders, |
|
| 52 | 2 | 'content' => $content, |
|
| 53 | 2 | 'timeout' => $this->timeout, |
|
| 54 | 'ignore_errors' => true |
||
| 55 | 2 | ] |
|
| 56 | 2 | ]; |
|
| 57 | |||
| 58 | 2 | $content = file_get_contents($url, false, stream_context_create($contextOptions)); |
|
| 59 | |||
| 60 | 2 | if (empty($http_response_header[0]) || strpos($http_response_header[0], '200') === false) |
|
| 61 | 2 | { |
|
| 62 | 1 | throw new RuntimeException($content); |
|
| 63 | } |
||
| 64 | |||
| 65 | 1 | return $content; |
|
| 66 | } |
||
| 67 | } |