Completed
Push — master ( faeafd...4dab11 )
by Josh
17:29
created

FirstAvailable::minify()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 16
ccs 6
cts 6
cp 1
rs 9.4286
cc 3
eloc 6
nc 3
nop 1
crap 3
1
<?php
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2015 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 ArrayAccess;
11
use Exception;
12
use RuntimeException;
13
use s9e\TextFormatter\Configurator\Collections\MinifierList;
14
use s9e\TextFormatter\Configurator\JavaScript\Minifier;
15
use s9e\TextFormatter\Configurator\Traits\CollectionProxy;
16
17
class FirstAvailable extends Minifier implements ArrayAccess
18
{
19
	use CollectionProxy;
20
21
	/**
22
	* @var MinifierList
23
	*/
24
	protected $collection;
25
26
	/**
27
	* Constructor
28
	*
29
	* @return void
30
	*/
31 6
	public function __construct()
32
	{
33 6
		$this->collection = new MinifierList;
34 6
		foreach (func_get_args() as $minifier)
35
		{
36 1
			$this->collection->add($minifier);
37 6
		}
38 6
	}
39
40
	/**
41
	* {@inheritdoc}
42
	*/
43 1
	public function getCacheDifferentiator()
44
	{
45 1
		return '';
46
	}
47
48
	/**
49
	* {@inheritdoc}
50
	*/
51 4
	public function minify($src)
52
	{
53 4
		foreach ($this->collection as $minifier)
54
		{
55
			try
56
			{
57 3
				return $minifier->minify($src);
58
			}
59 2
			catch (Exception $e)
60
			{
61
				// Do nothing
62
			}
63 3
		}
64
65 2
		throw new RuntimeException('No minifier available');
66
	}
67
}