Track   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 180
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 16
dl 0
loc 180
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A setTitle() 0 5 1
A __construct() 0 6 1
B getDomElement() 0 30 4
A getDuration() 0 3 1
A hasDuration() 0 3 1
A getImage() 0 3 1
A getTitle() 0 3 1
A setLocation() 0 5 1
A hasTitle() 0 3 1
A setImage() 0 5 1
A getLocation() 0 3 1
A setDuration() 0 5 1
A hasImage() 0 3 1
1
<?php
2
3
namespace Jalle19\xsphpf;
4
5
/**
6
 * Class Track
7
 * @package Jalle19\xsphpf
8
 */
9
class Track
10
{
11
12
    /**
13
     * @var string
14
     */
15
    private $location;
16
17
    /**
18
     * @var string|null
19
     */
20
    private $title;
21
22
    /**
23
     * @var int|null
24
     */
25
    private $duration;
26
27
    /**
28
     * @var string|null
29
     */
30
    private $image;
31
32
    /**
33
     * Track constructor.
34
     *
35
     * @param string      $location
36
     * @param null|string $title
37
     * @param int|null    $duration
38
     * @param null|string $image
39
     */
40
    public function __construct($location, $title = null, $duration = null, $image = null)
41
    {
42
        $this->location = $location;
43
        $this->title    = $title;
44
        $this->duration = $duration;
45
        $this->image    = $image;
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function getLocation()
52
    {
53
        return $this->location;
54
    }
55
56
    /**
57
     * @param string $location
58
     *
59
     * @return Track
60
     */
61
    public function setLocation($location)
62
    {
63
        $this->location = $location;
64
65
        return $this;
66
    }
67
68
    /**
69
     * @return null|string
70
     */
71
    public function getTitle()
72
    {
73
        return $this->title;
74
    }
75
76
    /**
77
     * @return bool
78
     */
79
    public function hasTitle()
80
    {
81
        return $this->title !== null;
82
    }
83
84
    /**
85
     * @param null|string $title
86
     *
87
     * @return Track
88
     */
89
    public function setTitle($title)
90
    {
91
        $this->title = $title;
92
93
        return $this;
94
    }
95
96
    /**
97
     * @return int|null
98
     */
99
    public function getDuration()
100
    {
101
        return $this->duration;
102
    }
103
104
    /**
105
     * @return bool
106
     */
107
    public function hasDuration()
108
    {
109
        return $this->duration !== null;
110
    }
111
112
    /**
113
     * @param int|null $duration
114
     *
115
     * @return Track
116
     */
117
    public function setDuration($duration)
118
    {
119
        $this->duration = $duration;
120
121
        return $this;
122
    }
123
124
    /**
125
     * @return null|string
126
     */
127
    public function getImage()
128
    {
129
        return $this->image;
130
    }
131
132
    /**
133
     * @return bool
134
     */
135
    public function hasImage()
136
    {
137
        return $this->image !== null;
138
    }
139
140
    /**
141
     * @param null|string $image
142
     *
143
     * @return Track
144
     */
145
    public function setImage($image)
146
    {
147
        $this->image = $image;
148
149
        return $this;
150
    }
151
152
    /**
153
     * Returns a DOMElement representing the track
154
     *
155
     * @param \DOMDocument $document the document the element will ultimately be appended to
156
     *
157
     * @return \DOMElement
158
     */
159
    public function getDomElement(\DOMDocument $document)
160
    {
161
        $track = $document->createElement('track');
162
163
        // Add the mandatory location element
164
        $location = $document->createElement('location');
165
        $location->appendChild($document->createCDATASection($this->getLocation()));
166
167
        $track->appendChild($location);
168
169
        // Add optional elements
170
        if ($this->hasTitle()) {
171
            $title = $document->createElement('title');
172
            $title->appendChild($document->createCDATASection($this->getTitle()));
173
            $track->appendChild($title);
174
        }
175
176
        if ($this->hasDuration()) {
177
            $duration = $document->createElement('duration');
178
            $duration->appendChild($document->createCDATASection($this->getDuration()));
179
            $track->appendChild($duration);
180
        }
181
182
        if ($this->hasImage()) {
183
            $image = $document->createElement('image');
184
            $image->appendChild($document->createCDATASection($this->getImage()));
185
            $track->appendChild($image);
186
        }
187
188
        return $track;
189
    }
190
191
}
192