Plus   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 54
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A shareUrl() 0 7 1
A shareCountRequest() 0 27 1
A shareCount() 0 6 2
1
<?php
2
3
namespace SocialLinks\Providers;
4
5
class Plus extends ProviderBase implements ProviderInterface
6
{
7
    /**
8
     * {@inheritdoc}
9
     */
10
    public function shareUrl()
11
    {
12
        return $this->buildUrl(
13
            'https://plus.google.com/share',
14
            array('url')
15
        );
16
    }
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function shareCountRequest()
22
    {
23
        $url = $this->page->getUrl();
24
25
        return static::request(
26
            'https://clients6.google.com/rpc',
27
            json_encode(
28
                array(
29
                    array(
30
                        'method' => 'pos.plusones.get',
31
                        'id' => 'p',
32
                        'params' => array(
33
                            'nolog' => true,
34
                            'id' => $url,
35
                            'source' => 'widget',
36
                            'userId' => '@viewer',
37
                            'groupId' => '@self',
38
                        ),
39
                        'jsonrpc' => '2.0',
40
                        'key' => 'p',
41
                        'apiVersion' => 'v1',
42
                    ),
43
                )
44
            ),
45
            array('Content-type: application/json')
46
        );
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function shareCount($response)
53
    {
54
        $count = static::jsonResponse($response);
55
56
        return isset($count[0]['result']['metadata']['globalCounts']['count']) ? intval($count[0]['result']['metadata']['globalCounts']['count']) : 0;
57
    }
58
}
59