Completed
Push — master ( fc377e...b5c4b2 )
by Oscar
01:46
created

Twitter::_shareCount()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
namespace SocialLinks\Providers;
4
5
class Twitter extends ProviderBase implements ProviderInterface
6
{
7
    /**
8
     * {@inheritdoc}
9
     */
10
    public function shareUrl()
11
    {
12
        $data = $this->page->get(array('title', 'twitterUser'));
13
        $text = isset($data['title']) ? trim($data['title']) : '';
14
15
        if (!empty($data['twitterUser']) && (strpos($text, $data['twitterUser']) === false)) {
16
            if (strrpos($text, '.', -1)) {
17
                $text = substr($text, 0, -1);
18
            }
19
20
            $text .= ' via '.$data['twitterUser'];
21
        }
22
23
        return $this->buildUrl(
24
            'https://twitter.com/intent/tweet',
25
            array('url'),
26
            array('text' => $text)
27
        );
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function _shareCountRequest()
34
    {
35
        return static::request(
36
            $this->buildUrl(
37
                'https://cdn.api.twitter.com/1/urls/count.json',
38
                array('url')
39
            )
40
        );
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function _shareCount($response)
47
    {
48
        $count = static::jsonResponse($response);
49
50
        return isset($count['count']) ? intval($count['count']) : 0;
51
    }
52
}
53