Odnoklassniki   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 2
dl 0
loc 61
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A shareUrl() 0 13 1
A shareCountRequest() 0 15 3
A shareCount() 0 10 2
1
<?php
2
3
namespace SocialLinks\Providers;
4
5
/**
6
 * Odnoklassniki is the second most popular Russian social network.
7
 */
8
class Odnoklassniki extends ProviderBase implements ProviderInterface
9
{
10
    protected $countField = 'share_ok';
11
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function shareUrl()
16
    {
17
        return $this->buildUrl('http://www.odnoklassniki.ru/dk',
18
            array(
19
                'description' => 'st.comments',
20
                'url' => 'st._surl',
21
            ),
22
            array(
23
                'st.cmd' => 'addShare',
24
                'st.s' => '1',
25
            )
26
        );
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function shareCountRequest()
33
    {
34
        // URLs starting with https:// seem to always return 0, so let's remove scheme from URL
35
        $urlParts = parse_url($this->page->getUrl());
36
37
        if (isset($urlParts['host'])) {
38
            $url = $urlParts['host'].(isset($urlParts['path']) ? $urlParts['path'] : '');
39
        } else {
40
            $url = $this->page->getUrl(); //fallback to original url
41
        }
42
43
        return static::request(
44
            $this->buildUrl('http://appsmail.ru/share/count/'.urlencode($url))
45
        );
46
    }
47
48
    /**
49
     * http://api.mail.ru/docs/reference/v4/sharecount/
50
     * Sample answer:
51
     * {
52
     *  "share_mm": 45037, // # of shares in my.mail.ru
53
     *  "share_ok": 14617 // # of shares in Odnoklassniki
54
     * }.
55
     *
56
     * {@inheritdoc}
57
     */
58
    public function shareCount($response)
59
    {
60
        $result = static::jsonResponse($response);
61
62
        if (isset($result->{$this->countField})) {
63
            return intval($result->{$this->countField});
64
        }
65
66
        return 0;
67
    }
68
}
69