Completed
Push — master ( c49bae...43ad9f )
by
unknown
09:25
created

VimeoProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 94.12%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A getIcon() 0 4 1
A parseProviderReference() 0 13 4
A getOembedUrl() 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 1
    public function parseProviderReference($value)
15
    {
16 1
        if (strpos($value, 'vimeo.com')) {
17 1
            $urlParts = explode('/', parse_url($value, PHP_URL_PATH));
18 1
            foreach ($urlParts as $urlPart) {
19 1
                if (ctype_digit($urlPart)) {
20 1
                    return $urlPart;
21
                }
22 1
            }
23
        }
24
25 1
        return $value;
26
    }
27
28
    /**
29
     * @param string $id
30
     * @return string
31
     */
32 1
    public function getOembedUrl($id)
33
    {
34 1
        return sprintf(self::URL_OEMBED, $id);
35
    }
36
37
    /**
38
     * @return string
39
     */
40 5
    public function getIcon()
41
    {
42 5
        return 'fa fa-vimeo';
43
    }
44
45
    /**
46
     * @return string
47
     */
48 5
    public function getName()
49
    {
50 5
        return 'vimeo';
51
    }
52
53
    /**
54
     * @return string
55
     */
56 1
    public function getType()
57
    {
58 1
        return AbstractProvider::TYPE_VIDEO;
59
    }
60
}
61