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

Twitter   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 48
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B shareUrl() 0 19 5
A _shareCountRequest() 0 9 1
A _shareCount() 0 6 2
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