LinkedIn   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 4 4 1
A getLink() 7 7 1
A getShares() 6 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
 * LinkedIn.
16
 *
17
 * @author Morrison Laju <[email protected]>
18
 */
19 View Code Duplication
class LinkedIn 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 = 'linkedin';
22
    const SHARE_URL = 'https://www.linkedin.com/shareArticle?%s';
23
    const API_URL = 'https://www.linkedin.com/countserv/count/share?url=%s&format=json';
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function getName()
29
    {
30
        return self::NAME;
31
    }
32
33
    /**
34
     * Gets the share link for the URL.
35
     *
36
     * @param array  $options This provider supports the following options:<pre>
37
     *                        title: the title
38
     *                        summary: the summary
39
     *                        source: the source
40
     *                        </pre>
41
     * @param string $url
42
     * @param array  $options
43
     *
44
     * @return string
45
     */
46
    public function getLink($url, array $options = array())
47
    {
48
        $options['mini'] = 'true';
49
        $options['url'] = $url;
50
51
        return sprintf(self::SHARE_URL, http_build_query($options, null, '&'));
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function getShares($url)
58
    {
59
        $data = json_decode(file_get_contents(sprintf(self::API_URL, urlencode($url))));
60
61
        return intval($data->count);
62
    }
63
}
64