Playlist   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 9
c 2
b 0
f 1
dl 0
loc 57
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addItem() 0 3 1
A getSanitizedFileName() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
use Behat\Transliterator\Transliterator;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Transliterator. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
4
5
/**
6
 * Represents a generic playlist
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
abstract class Playlist
13
{
14
15
	const TYPE_M3U = 'm3u';
16
	const TYPE_XSPF = 'xspf';
17
	const TYPE_PLS = 'pls';
18
19
	/**
20
	 * @var PlaylistItem[] the playlist items
21
	 */
22
	protected $_items = array();
23
24
	/**
25
	 * @var string the playlist filename
26
	 */
27
	private $_fileName;
28
29
	/**
30
	 * @return string the file extension of the playlist
31
	 */
32
	abstract public function getExtension();
33
	
34
	/**
35
	 * @return string the MIME type of the playlist
36
	 */
37
	abstract public function getMIMEType();
38
39
	/**
40
	 * @return string the actual playlist data
41
	 */
42
	abstract public function __toString();
43
44
	/**
45
	 * Class constructor
46
	 * @param string $fileName the playlist filename
47
	 */
48
	public function __construct($fileName)
49
	{
50
		$this->_fileName = $fileName;
51
	}
52
53
	/**
54
	 * Adds an item to the playlist
55
	 * @param PlaylistItem $item the item
56
	 */
57
	public function addItem($item)
58
	{
59
		$this->_items[] = $item;
60
	}
61
62
	/**
63
	 * Returns the filename sanitized to minimize issues with various platforms
64
	 * @return string the sanitized filename
65
	 */
66
	public function getSanitizedFileName()
67
	{
68
		return Transliterator::transliterate($this->_fileName).'.'.$this->getExtension();
69
	}
70
71
}
72