Facebook::getLink()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
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
 * Facebook.
16
 *
17
 * @author Kévin Dunglas <[email protected]>
18
 */
19
class Facebook implements ProviderInterface
20
{
21
    const NAME = 'facebook';
22
    const SHARE_URL = 'https://www.facebook.com/sharer/sharer.php?u=%s';
23
    const API_URL = 'https://graph.facebook.com/?id=%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
        return sprintf(self::SHARE_URL, urlencode($url));
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getShares($url)
45
    {
46
        $data = json_decode(file_get_contents(sprintf(self::API_URL, urlencode($url))));
47
48
        if (isset($data->likes)) {
49
            return intval($data->likes);
50
        }
51
        if (isset($data->shares)) {
52
            return intval($data->shares);
53
        }
54
55
        return 0;
56
    }
57
}
58