GruntClientScript   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 44
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A registerCssFile() 0 6 2
A registerScriptFile() 0 6 2
A isBundled() 0 9 3
1
<?php
2
3
/**
4
 * Client script implemenation which works side by side with Grunt. It makes it 
5
 * possible to define a list of scripts and styles that are included in a 
6
 * compiled file. These files will not be registered separately.
7
 *
8
 * @author Sam Stenvall <[email protected]>
9
 * @copyright Copyright &copy; Sam Stenvall 2013-
10
 * @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0
11
 */
12
class GruntClientScript extends CClientScript
13
{
14
15
	/**
16
	 * @var array list of bundled files
17
	 */
18
	public $bundledFiles = array();
19
20
	/**
21
	 * {@inheritDoc}
22
	 */
23
	public function registerScriptFile($url, $position = null, array $htmlOptions = array())
24
	{
25
		if ($this->isBundled($url))
26
			return $this;
27
28
		return parent::registerScriptFile($url, $position, $htmlOptions);
29
	}
30
	
31
	/**
32
	 * {@inheritDoc}
33
	 */
34
	public function registerCssFile($url, $media = '')
35
	{
36
		if ($this->isBundled($url))
37
			return $this;
38
39
		return parent::registerCssFile($url, $media);
40
	}
41
42
	/**
43
	 * Checks whether a particular URL should be registered or not
44
	 * @param string $url the asset URL
45
	 * @return boolean whether the item is bundled
46
	 */
47
	private function isBundled($url)
48
	{
49
		foreach ($this->bundledFiles as $name)
50
		{
51
			if (substr($url, -(strlen($name))) === $name)
52
				return true;
53
		}
54
55
		return false;
56
	}
57
58
}
59