Passed
Push — master ( 3bf788...763f00 )
by Jon
02:39 queued 10s
created

Audio::setImageUrl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php namespace FlatPlan\Components;
2
3
class Audio extends AbstractComponent {
4
5
    private $url;
6
    private $role;
7
    private $caption;
8
    private $accessibilityCaption;
9
    private $expicitContent;
10
    private $imageUrl;
11
12
    protected $roles   = ['audio', 'music'];
13
14
    /**
15
     * @param string $url
16
     * @param string $role
17
     * @param string $caption
18
     * @param string $accessibilityCaption
19
     * @param bool $explicitContent
20
     * @param string $imageUrl
21
     * @return void
22
     */
23
    public function __construct($url, $role, $caption, $accessibilityCaption = '', $explicitContent = false, $imageUrl = '')
24
    {
25
        $this->setUrl($url);
26
        $this->setRole($role);
27
        $this->setCaption($caption);
28
        $this->setAccessibilityCaption($accessibilityCaption);
29
        $this->setExplicitContent($explicitContent);
30
        $this->setImageUrl($imageUrl);
31
    }
32
33
    public function setUrl($url)
34
    {
35
        if (!filter_var($url, FILTER_VALIDATE_URL)) {
36
            throw new \ErrorException('Invalid url supplied.');
37
        }
38
        $this->url = $url;
39
    }
40
41
    public function getUrl()
42
    {
43
        return $this->url;
44
    }
45
46
    public function setRole($role)
47
    {
48
        if (!in_array($role, $this->roles)) {
49
            throw new \ErrorException('Invalid role supplied.');
50
        }
51
        $this->role = $role;
52
    }
53
54
    public function getRole()
55
    {
56
        return $this->role;
57
    }
58
59
    public function setCaption($caption)
60
    {
61
        $this->caption = $caption;
62
    }
63
64
    public function getCaption()
65
    {
66
        return $this->caption;
67
    }
68
69
    public function setAccessibilityCaption($accessibilityCaption)
70
    {
71
        $this->accessibilityCaption = $accessibilityCaption;
72
    }
73
74
    public function getAccessibilityCaption()
75
    {
76
        return $this->accessibilityCaption;
77
    }
78
79
    public function setExplicitContent($expicitContent)
80
    {
81
        $this->expicitContent = $expicitContent;
82
    }
83
84
    public function getExplicitContent()
85
    {
86
        return $this->expicitContent;
87
    }
88
89
    public function setImageUrl($imageUrl)
90
    {
91
        if (!filter_var($imageUrl, FILTER_VALIDATE_URL)) {
92
            throw new \ErrorException('Invalid url supplied.');
93
        }
94
        $this->imageUrl = $imageUrl;
95
    }
96
97
    public function getImageUrl()
98
    {
99
        return $this->imageUrl;
100
    }
101
102
    public function getComponent()
103
    {
104
        $component = new \stdClass();
105
        $component->url                  = $this->getUrl();
106
        $component->role                 = $this->getRole();
107
        $component->caption              = $this->getCaption();
108
        $component->accessibilityCaption = $this->getAccessibilityCaption();
109
        $component->expicitContent       = $this->getExplicitContent();
110
        $component->imageUrl             = $this->getImageUrl();
111
        return $component;
112
    }
113
114
    public function __toString()
115
    {
116
        return json_encode($this->getComponent());
117
    }
118
}
119