1 | <?php |
||
15 | class VimeoServiceAdapter extends AbstractServiceAdapter |
||
16 | { |
||
17 | const THUMBNAIL_SMALL = 'thumbnail_small'; |
||
|
|||
18 | const THUMBNAIL_MEDIUM = 'thumbnail_medium'; |
||
19 | const THUMBNAIL_LARGE = 'thumbnail_large'; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | public $title; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | public $description; |
||
30 | |||
31 | /** |
||
32 | * @var array |
||
33 | */ |
||
34 | public $thumbnails; |
||
35 | |||
36 | /** |
||
37 | * @param string $url |
||
38 | * @param string $pattern |
||
39 | * @param EmbedRendererInterface $renderer |
||
40 | */ |
||
41 | 12 | public function __construct($url, $pattern, EmbedRendererInterface $renderer) |
|
42 | { |
||
43 | 12 | $videoId = $this->getVideoIdByPattern($url, $pattern); |
|
44 | 12 | $this->setVideoId($videoId); |
|
45 | 12 | $videoData = $this->getVideoDataFromServiceApi(); |
|
46 | |||
47 | 12 | $this->setThumbnails(array( |
|
48 | 12 | self::THUMBNAIL_SMALL => $videoData[self::THUMBNAIL_SMALL], |
|
49 | 12 | self::THUMBNAIL_MEDIUM => $videoData[self::THUMBNAIL_MEDIUM], |
|
50 | 12 | self::THUMBNAIL_LARGE => $videoData[self::THUMBNAIL_LARGE], |
|
51 | 12 | )); |
|
52 | |||
53 | 12 | $this->setTitle($videoData['title']); |
|
54 | 12 | $this->setDescription($videoData['description']); |
|
55 | |||
56 | 12 | return parent::__construct($url, $pattern, $renderer); |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * Returns the service name (ie: "Youtube" or "Vimeo"). |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | 1 | public function getServiceName() |
|
65 | { |
||
66 | 1 | return 'Vimeo'; |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * Returns if the service has a thumbnail image. |
||
71 | * |
||
72 | * @return bool |
||
73 | */ |
||
74 | 1 | public function hasThumbnail() |
|
78 | |||
79 | /** |
||
80 | * @return string |
||
81 | */ |
||
82 | 1 | public function getTitle() |
|
86 | |||
87 | /** |
||
88 | * @param string $title |
||
89 | */ |
||
90 | 12 | public function setTitle($title) |
|
94 | |||
95 | /** |
||
96 | * @return string |
||
97 | */ |
||
98 | 1 | public function getDescription() |
|
102 | |||
103 | /** |
||
104 | * @param string $description |
||
105 | */ |
||
106 | 12 | public function setDescription($description) |
|
110 | |||
111 | /** |
||
112 | * @param array $thumbnails |
||
113 | */ |
||
114 | 1 | private function setThumbnails(array $thumbnails) |
|
120 | |||
121 | /** |
||
122 | 12 | * @param string $size |
|
123 | * |
||
124 | 12 | * @return string |
|
125 | 12 | * |
|
126 | * @throws InvalidThumbnailSizeException |
||
127 | */ |
||
128 | public function getThumbnail($size, $secure = false) |
||
136 | 2 | ||
137 | 1 | /** |
|
138 | * @param bool $autoplay |
||
139 | * |
||
140 | 1 | * @return string |
|
141 | */ |
||
142 | public function getEmbedUrl($autoplay = false, $secure = false) |
||
146 | |||
147 | /** |
||
148 | 1 | * Returns all thumbnails available sizes. |
|
149 | * |
||
150 | 1 | * @return array |
|
151 | */ |
||
152 | public function getThumbNailSizes() |
||
160 | |||
161 | 3 | /** |
|
162 | 3 | * Returns the small thumbnail's url. |
|
163 | 3 | * |
|
164 | 3 | * @param bool $secure |
|
165 | * @return string |
||
166 | * @throws InvalidThumbnailSizeException |
||
167 | */ |
||
168 | public function getSmallThumbnail($secure = false) |
||
172 | 1 | ||
173 | /** |
||
174 | 1 | * Returns the medium thumbnail's url. |
|
175 | * |
||
176 | * @param bool $secure |
||
177 | * @return string |
||
178 | * @throws InvalidThumbnailSizeException |
||
179 | */ |
||
180 | public function getMediumThumbnail($secure = false) |
||
184 | 1 | ||
185 | /** |
||
186 | * Returns the large thumbnail's url. |
||
187 | * |
||
188 | * @param bool $secure |
||
189 | * @param $secure |
||
190 | * @return string |
||
191 | * @throws InvalidThumbnailSizeException |
||
192 | 1 | */ |
|
193 | public function getLargeThumbnail($secure = false) |
||
197 | |||
198 | /** |
||
199 | * Returns the largest thumnbnaail's url. |
||
200 | * |
||
201 | * @param bool $secure |
||
202 | 1 | * @param $secure |
|
203 | * @return string |
||
204 | 1 | * @throws InvalidThumbnailSizeException |
|
205 | */ |
||
206 | public function getLargestThumbnail($secure = false) |
||
210 | 1 | ||
211 | /** |
||
212 | 1 | * @return bool |
|
213 | */ |
||
214 | public function isEmbeddable() |
||
218 | |||
219 | /** |
||
220 | * @param string $url |
||
221 | 12 | * @param string $pattern |
|
222 | * |
||
223 | 12 | * @return int |
|
224 | 12 | */ |
|
225 | 12 | private function getVideoIdByPattern($url, $pattern) |
|
233 | |||
234 | /** |
||
235 | * Uses the Vimeo video API to get video info. |
||
236 | * |
||
237 | * @todo make this better by using guzzle |
||
238 | * |
||
239 | 12 | * @return array |
|
240 | * |
||
241 | 12 | * @throws ServiceApiNotAvailable |
|
242 | 12 | */ |
|
243 | private function getVideoDataFromServiceApi() |
||
253 | } |
||
254 |
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.