VimeoProvider   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

5 Methods

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