Completed
Push — master ( 10991b...345e86 )
by
unknown
05:55
created

VimeoProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 1
dl 0
loc 56
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A parseProviderReference() 0 13 4
A getOembedUrl() 0 4 1
A getIcon() 0 4 1
A getName() 0 4 1
A getType() 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 getName()
49
    {
50
        return 'vimeo';
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getType()
57
    {
58
        return AbstractProvider::TYPE_VIDEO;
59
    }
60
}
61