Completed
Push — master ( b82ab1...166118 )
by Josh
27:32 queued 21:51
created

HostedMinifier::minify()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 16
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 10
nc 4
nop 1
crap 12
1
<?php
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2017 The s9e Authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\TextFormatter\Configurator\JavaScript\Minifiers;
9
10
use RuntimeException;
11
use s9e\TextFormatter\Configurator\JavaScript\OnlineMinifier;
12
13
class HostedMinifier extends OnlineMinifier
14
{
15
	/**
16
	* @var integer Compression level used to compress the request's payload
17
	*/
18
	public $gzLevel = 5;
19
20
	/**
21
	* @var string Minifier service's URL
22
	*/
23
	public $url = 'http://s9e-textformatter.rhcloud.com/minifier/';
24
25
	/**
26
	* {@inheritdoc}
27
	*/
28
	public function minify($src)
29
	{
30
		$headers = ['Content-Type: application/octet-stream'];
31
		$body    = $src;
32
		if (extension_loaded('zlib'))
33
		{
34
			$headers[] = 'Content-Encoding: gzip';
35
			$body      = gzencode($body, $this->gzLevel);
36
		}
37
38
		$code = $this->httpClient->post($this->url, $headers, $body);
39
		if ($code === false)
40
		{
41
			throw new RuntimeException;
42
		}
43
44
		return $code;
45
	}
46
}