1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: Ricardo Fiorani |
5
|
|
|
* Date: 29/08/2015 |
6
|
|
|
* Time: 19:37. |
7
|
|
|
*/ |
8
|
|
|
namespace RicardoFiorani\Adapter; |
9
|
|
|
|
10
|
|
|
use RicardoFiorani\Exception\NotEmbeddableException; |
11
|
|
|
use RicardoFiorani\Renderer\EmbedRendererInterface; |
12
|
|
|
|
13
|
|
|
abstract class AbstractServiceAdapter implements VideoAdapterInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
public $rawUrl; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
public $videoId; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
public $pattern; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var EmbedRendererInterface |
32
|
|
|
*/ |
33
|
|
|
public $renderer; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* AbstractVideoAdapter constructor. |
37
|
|
|
* |
38
|
|
|
* @param string $url |
39
|
|
|
* @param string $pattern |
40
|
|
|
* @param EmbedRendererInterface $renderer |
41
|
|
|
*/ |
42
|
51 |
|
public function __construct($url, $pattern, EmbedRendererInterface $renderer) |
43
|
|
|
{ |
44
|
51 |
|
$this->rawUrl = $url; |
|
|
|
|
45
|
51 |
|
$this->pattern = $pattern; |
|
|
|
|
46
|
51 |
|
$this->renderer = $renderer; |
47
|
51 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Returns the input URL. |
51
|
|
|
* |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
2 |
|
public function getRawUrl() |
55
|
|
|
{ |
56
|
2 |
|
return $this->rawUrl; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $rawUrl |
61
|
|
|
*/ |
62
|
1 |
|
public function setRawUrl($rawUrl) |
63
|
|
|
{ |
64
|
1 |
|
$this->rawUrl = $rawUrl; |
65
|
1 |
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
17 |
|
public function getVideoId() |
71
|
|
|
{ |
72
|
17 |
|
return $this->videoId; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param string $videoId |
77
|
|
|
*/ |
78
|
51 |
|
public function setVideoId($videoId) |
79
|
|
|
{ |
80
|
51 |
|
$this->videoId = $videoId; |
81
|
51 |
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
2 |
|
public function getPattern() |
87
|
|
|
{ |
88
|
2 |
|
return $this->pattern; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param string $pattern |
93
|
|
|
*/ |
94
|
1 |
|
public function setPattern($pattern) |
95
|
|
|
{ |
96
|
1 |
|
$this->pattern = $pattern; |
97
|
1 |
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return EmbedRendererInterface |
101
|
|
|
*/ |
102
|
2 |
|
public function getRenderer() |
103
|
|
|
{ |
104
|
2 |
|
return $this->renderer; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param EmbedRendererInterface $renderer |
109
|
|
|
*/ |
110
|
1 |
|
public function setRenderer($renderer) |
111
|
|
|
{ |
112
|
1 |
|
$this->renderer = $renderer; |
113
|
1 |
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param int $width |
117
|
|
|
* @param int $height |
118
|
|
|
* @param bool $autoplay |
119
|
|
|
* |
120
|
|
|
* @return string |
121
|
|
|
* |
122
|
|
|
* @throws NotEmbeddableException |
123
|
|
|
*/ |
124
|
1 |
|
public function getEmbedCode($width, $height, $autoplay = false, $secure = false) |
125
|
|
|
{ |
126
|
1 |
|
if (false == $this->isEmbeddable()) { |
|
|
|
|
127
|
|
|
throw new NotEmbeddableException(); |
128
|
|
|
} |
129
|
|
|
|
130
|
1 |
|
return $this->getRenderer()->renderVideoEmbedCode($this->getEmbedUrl($autoplay, $secure), $width, $height); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Switches the protocol scheme between http and https |
135
|
|
|
* |
136
|
|
|
* @param bool|false $secure |
137
|
|
|
* @return string |
138
|
|
|
*/ |
139
|
|
|
public function getScheme($secure = false) |
140
|
|
|
{ |
141
|
|
|
return ($secure ? 'https' : 'http'); |
142
|
|
|
} |
143
|
|
|
} |
|
|
|
|
144
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.