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

FirstAvailable   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 51
ccs 14
cts 14
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getCacheDifferentiator() 0 4 1
A minify() 0 16 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
}