Completed
Push — master ( e06bc5...43b9f7 )
by Josh
17:33
created

FirstAvailable::getCacheDifferentiator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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 4
	public function minify($src)
44
	{
45 4
		foreach ($this->collection as $minifier)
46
		{
47
			try
48
			{
49 3
				return $minifier->minify($src);
50
			}
51 2
			catch (Exception $e)
52
			{
53
				// Do nothing
54
			}
55 3
		}
56
57 2
		throw new RuntimeException('No minifier available');
58
	}
59
}