Completed
Push — master ( e06bc5...43b9f7 )
by Josh
17:33
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 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 16
ccs 6
cts 6
cp 1
rs 9.4286
nc 3
cc 3
eloc 6
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 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
}