Twitter::getLink()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 6
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
 * Twitter.
16
 *
17
 * @author Kévin Dunglas <[email protected]>
18
 */
19 View Code Duplication
class Twitter implements ProviderInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
{
21
    const NAME = 'twitter';
22
    const SHARE_URL = 'https://twitter.com/intent/tweet?%s';
23
    const API_URL = 'https://cdn.api.twitter.com/1/urls/count.json?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))));
49
50
        return intval($data->count);
51
    }
52
}
53