Completed
Push — master ( d3fff0...eb77f8 )
by
unknown
10:47
created

VimeoProvider   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 61
ccs 0
cts 32
cp 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A parseProviderReference() 0 13 4
A getOembedUrl() 0 4 1
A getIcon() 0 4 1
A getTitle() 0 4 1
A getType() 0 4 1
A getEmbedTemplate() 0 4 1
1
<?php
2
3
namespace MediaMonks\SonataMediaBundle\Provider;
4
5
class VimeoProvider extends AbstractOembedProvider implements OembedProviderInterface
6
{
7
    const URL_OEMBED = 'https://vimeo.com/api/oembed.json?url=http://vimeo.com/%s';
8
9
    /**
10
     * @param $value
11
     * @return string
12
     * @throws \Exception
13
     */
14
    public function parseProviderReference($value)
15
    {
16
        if (strpos($value, 'vimeo.com')) {
17
            $urlParts = explode('/', parse_url($value, PHP_URL_PATH));
18
            foreach ($urlParts as $urlPart) {
19
                if (ctype_digit($urlPart)) {
20
                    return $urlPart;
21
                }
22
            }
23
        }
24
25
        return $value;
26
    }
27
28
    /**
29
     * @param string $id
30
     * @return string
31
     */
32
    public function getOembedUrl($id)
33
    {
34
        return sprintf(self::URL_OEMBED, $id);
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    public function getIcon()
41
    {
42
        return 'fa fa-vimeo';
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function getTitle()
49
    {
50
        return 'Vimeo Video';
51
    }
52
53
    public function getType()
54
    {
55
        return 'vimeo';
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getEmbedTemplate()
62
    {
63
        return 'MediaMonksSonataMediaBundle:Provider:vimeo_embed.html.twig';
64
    }
65
}
66