PlaylistFactory   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 16
c 2
b 0
f 1
dl 0
loc 43
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTypes() 0 6 1
A __construct() 0 2 1
A create() 0 15 5
1
<?php
2
3
/**
4
 * Playlist factory
5
 *
6
 * @author Sam Stenvall <[email protected]>
7
 * @copyright Copyright &copy; Sam Stenvall 2013-
8
 * @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0
9
 */
10
class PlaylistFactory
11
{
12
13
	private function __construct()
14
	{
15
		
16
	}
17
18
	/**
19
	 * Factory method for creating playlist objects
20
	 * @param string $fileName
21
	 * @param string $format the desired playlist format. Defaults to null, 
22
	 * meaning the configured default format will be used
23
	 * @return Playlist the playlist object
24
	 * @throws InvalidRequestException if the playlist format is not supported
25
	 */
26
	public static function create($fileName, $format = null)
27
	{
28
		if ($format === null)
29
			$format = Setting::getString('playlistFormat');
30
31
		switch ($format)
32
		{
33
			case Playlist::TYPE_M3U:
34
				return new M3UPlaylist($fileName);
35
			case Playlist::TYPE_XSPF:
36
				return new XSPFPlaylist($fileName);
37
			case Playlist::TYPE_PLS:
38
				return new PLSPlaylist($fileName);
39
			default:
40
				throw new InvalidRequestException();
41
		}
42
	}
43
44
	/**
45
	 * @return array the valid playlist formats
46
	 */
47
	public static function getTypes()
48
	{
49
		return array(
50
			Playlist::TYPE_M3U=>'M3U',
51
			Playlist::TYPE_PLS=>'PLS',
52
			Playlist::TYPE_XSPF=>'XSPF',
53
		);
54
	}
55
56
}
57