StumbleUpon   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 4
c 3
b 1
f 1
lcom 0
cbo 0
dl 0
loc 34
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A getLink() 0 6 1
A getShares() 0 6 2
1
<?php
2
3
/*
4
 * This file is part of the SocialShare package.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace SocialShare\Provider;
13
14
/**
15
 * StumbleUpon.
16
 *
17
 * @author Morrison Laju <[email protected]>
18
 */
19
class StumbleUpon implements ProviderInterface
20
{
21
    const NAME = 'stumbleupon';
22
    const SHARE_URL = 'https://www.stumbleupon.com/badge/?%s';
23
    const API_URL = 'https://www.stumbleupon.com/services/1.01/badge.getinfo?url=%s';
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function getName()
29
    {
30
        return self::NAME;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function getLink($url, array $options = array())
37
    {
38
        $options['url'] = $url;
39
40
        return sprintf(self::SHARE_URL, http_build_query($options, null, '&'));
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function getShares($url)
47
    {
48
        $data = json_decode(file_get_contents(sprintf(self::API_URL, urlencode($url))), true);
49
50
        return isset($data['result']['views']) ? intval($data['result']['views']) : 0;
51
    }
52
}
53