Facebook   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 7
Bugs 4 Features 0
Metric Value
wmc 5
c 7
b 4
f 0
lcom 0
cbo 0
dl 0
loc 39
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A getLink() 0 4 1
A getShares() 0 13 3
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