Reddit::shareUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SocialLinks\Providers;
4
5
class Reddit extends ProviderBase implements ProviderInterface
6
{
7
    /**
8
     * {@inheritdoc}
9
     */
10
    public function shareUrl()
11
    {
12
        return $this->buildUrl(
13
            'https://www.reddit.com/submit',
14
            array('url', 'title')
15
        );
16
    }
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function shareCountRequest()
22
    {
23
        return static::request(
24
            $this->buildUrl(
25
                'https://www.reddit.com/api/info.json',
26
                array('url')
27
            )
28
        );
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function shareCount($response)
35
    {
36
        $count = static::jsonResponse($response);
37
        $score = 0;
38
39
        if (isset($count['data']['children'][0])) {
40
            foreach ($count['data']['children'] as $child) {
41
                $score += isset($child['data']['score']) ? intval($child['data']['score']) : 0;
42
            }
43
        }
44
45
        return $score;
46
    }
47
}
48