Completed
Push — master ( 9898d5...71064b )
by Josh
18:52
created

RemoteCache   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 88.89%

Importance

Changes 4
Bugs 1 Features 2
Metric Value
wmc 3
c 4
b 1
f 2
lcom 1
cbo 2
dl 0
loc 35
ccs 8
cts 9
cp 0.8889
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getHash() 0 4 1
A minify() 0 11 2
1
<?php
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2016 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 RemoteCache extends OnlineMinifier
14
{
15
	/**
16
	* @var string Minifier service's URL
17
	*/
18
	public $url = 'http://s9e-textformatter.rhcloud.com/minifier/';
19
20
	/**
21
	* {@inheritdoc}
22
	*/
23 1
	public function minify($src)
24
	{
25 1
		$url  = $this->url . '?hash=' . $this->getHash($src);
26 1
		$code = $this->getHttpClient()->get($url);
27 1
		if ($code === false)
28 1
		{
29 1
			throw new RuntimeException;
30
		}
31
32
		return $code;
33
	}
34
35
	/**
36
	* Compute a source's hash
37
	*
38
	* 160 bits of SHA1 + 128 bits of MD5, base64-encoded to a 48 bytes string
39
	*
40
	* @param  string $src Original source
41
	* @return string      48 bytes string
42
	*/
43 1
	protected function getHash($src)
44
	{
45 1
		return strtr(base64_encode(sha1($src, true) . md5($src, true)), '+/', '-_');
46
	}
47
}