Passed
Push — master ( 43a084...7e18cf )
by Jon
01:56
created

Video::getCaption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php namespace FlatPlan\Components;
2
3
class Video extends AbstractComponent {
4
5
    protected $url;
6
    protected $aspectRatio;
7
    protected $caption;
8
    protected $accessibilityCaption;
9
    protected $explicitContent;
10
11
    protected $roles   = ['video', 'embedwebvideo', 'embedvideo'];
12
13
    /**
14
     * @param string $role
15
     * @param string $url
16
     * @param float $aspectRatio
17
     * @param string $caption
18
     * @param string $accessibilityCaption
19
     * @param bool $explicitContent
20
     * @param string $stillUrl
21
     * @return void
22
     */
23
    public function __construct($role, $url, $aspectRatio = 1.777, $caption = '', $accessibilityCaption = '', $explicitContent = false, $stillUrl = null)
24
    {
25
        $this->setRole($role);
26
        $this->setUrl($url);
27
        $this->setAspectRatio($aspectRatio);
28
        $this->setCaption($caption);
29
        $this->setAccessibilityCaption($accessibilityCaption);
30
        $this->setExplicitContent($explicitContent);
31
        if (!is_null($stillUrl)) {
32
            $this->setStillUrl($stillUrl);
33
        }
34
    }
35
36
    private function setUrl($url)
37
    {
38
        if (!filter_var($url, FILTER_VALIDATE_URL)) {
39
            throw new \ErrorException('Invalid url supplied.');
40
        }
41
        $this->url = $url;
42
    }
43
44
    private function getUrl()
45
    {
46
        return $this->url;
47
    }
48
49
    private function setAspectRatio($aspectRatio)
50
    {
51
        $this->aspectRatio = (float) $aspectRatio;
52
    }
53
54
    private function getAspectRatio()
55
    {
56
        return $this->aspectRatio;
57
    }
58
59
    private function setCaption($caption)
60
    {
61
        $this->caption = $caption;
62
    }
63
64
    private function getCaption()
65
    {
66
        return $this->caption;
67
    }
68
69
    private function setAccessibilityCaption($accessibilityCaption)
70
    {
71
        $this->accessibilityCaption = $accessibilityCaption;
72
    }
73
74
    private function getAccessibilityCaption()
75
    {
76
        return $this->accessibilityCaption;
77
    }
78
79
    private function setExplicitContent($explicitContent)
80
    {
81
        $this->explicitContent = $explicitContent;
82
    }
83
84
    private function getExplicitContent()
85
    {
86
        return $this->explicitContent;
87
    }
88
89
    private function setStillUrl($url)
90
    {
91
        if (!filter_var($url, FILTER_VALIDATE_URL)) {
92
            throw new \ErrorException('Invalid still url supplied.');
93
        }
94
        $this->stillUrl = $url;
0 ignored issues
show
Bug Best Practice introduced by
The property stillUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
95
    }
96
97
    private function getStillUrl()
98
    {
99
        return $this->stillUrl;
100
    }
101
102
    public function getComponent()
103
    {
104
        $component = new \stdClass();
105
        $component->URL                  = $this->getUrl();
106
        $component->role                 = $this->getRole();
107
        $component->aspectRatio          = $this->getAspectRatio();
108
        $component->caption              = $this->getCaption();
109
        $component->accessibilityCaption = $this->getAccessibilityCaption();
110
        $component->explicitContent      = $this->getExplicitContent();
111
        if ($component->role === 'video') {
112
            $component->stillURL = $this->getStillUrl();
113
        }
114
        $component->layout               = $this->layout;
115
        $component->style                = $this->style;
116
        if (!is_null($this->behaviour)) {
117
            $component->behaviour = $this->getBehaviour();
118
        }
119
        return $component;
120
    }
121
}
122