Completed
Push — master ( c7b78a...21ab66 )
by Jacques
15s queued 12s
created

YoutubeVideoTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
c 1
b 0
f 0
dl 0
loc 23
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getVideoIframeURLFromPublicURL() 0 15 3
1
<?php
2
declare(strict_types=1);
3
4
namespace MonsieurBiz\SyliusRichEditorPlugin\UiElement;
5
6
trait YoutubeVideoTrait
7
{
8
9
    /**
10
     * @param string $url
11
     *
12
     * @return string|null
13
     */
14
    public function getVideoIframeURLFromPublicURL(string $url): ?string
15
    {
16
        // Already embedded
17
        if (\strpos($url, 'www.youtube.com/embed') !== false) {
18
            return $url;
19
        }
20
21
        $query = \parse_url($url, PHP_URL_QUERY);
22
        \parse_str($query, $params);
23
24
        if (!isset($params['v'])) {
25
            return null;
26
        }
27
28
        return \sprintf('https://www.youtube.com/embed/%s', $params['v']);
29
    }
30
31
}
32