Passed
Push — master ( abe9d4...f9c79d )
by Vladimir
04:18
created

Twitter::getLink()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 12
nc 2
nop 0
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @link https://github.com/yiimaker/yii2-social-share
4
 * @copyright Copyright (c) 2017 Yii Maker
5
 * @license BSD 3-Clause License
6
 */
7
8
namespace ymaker\social\share\drivers;
9
10
use ymaker\social\share\base\DriverAbstract;
11
12
/**
13
 * DriverAbstract for Twitter.
14
 * @link https://twitter.com
15
 *
16
 * @author Vladimir Kuprienko <[email protected]>
17
 * @since 1.0
18
 */
19
class Twitter extends DriverAbstract
20
{
21
    /**
22
     * @var bool|string
23
     */
24
    public $account = false;
25
26
27
    /**
28
     * @inheritdoc
29
     */
30
    protected function processShareData()
31
    {
32
        $this->url = static::encodeData($this->url);
33
        $this->description = static::encodeData($this->description);
34
35
        if (is_string($this->account)) {
36
            $this->appendToData('account', $this->account);
37
        }
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43
    protected function buildLink()
44
    {
45
        $link = 'http://twitter.com/share?url={url}&text={description}';
46
47
        if ($this->account) {
48
            $this->addUrlParam($link, 'via', '{account}');
49
        }
50
51
        return $link;
52
    }
53
54
    /**
55
     * @inheritdoc
56
     */
57
    protected function getMetaTags()
58
    {
59
        return [
60
            ['name' => 'twitter:card',         'content' => 'summary_large_image'],
61
            ['name' => 'twitter:title',        'content' => '{title}'],
62
            ['name' => 'twitter:description',  'content' => '{description}'],
63
            ['name' => 'twitter:image',        'content' => '{imageUrl}']
64
        ];
65
    }
66
}
67