StumbleUpon::getLink()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 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