Telegram::buildLink()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * @link https://github.com/yiimaker/yii2-social-share
5
 * @copyright Copyright (c) 2017-2021 Volodymyr Kupriienko
6
 * @license BSD 3-Clause License
7
 */
8
9
namespace ymaker\social\share\drivers;
10
11
use ymaker\social\share\base\AbstractDriver;
12
13
/**
14
 * Driver for Telegram messenger.
15
 *
16
 * @see https://telegram.org
17
 *
18
 * @author Vladimir Kuprienko <[email protected]>
19
 *
20
 * @since 1.0
21
 */
22
class Telegram extends AbstractDriver
23
{
24
    /**
25
     * @var bool|string
26
     */
27
    public $message = false;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    protected function processShareData()
33
    {
34
        $this->url = static::encodeData($this->url);
35
36
        if (\is_string($this->message)) {
37
            $this->appendToData('message', $this->message);
38
        }
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    protected function buildLink()
45
    {
46
        $link = 'https://telegram.me/share/url?url={url}';
47
48
        if ($this->message) {
49
            $this->addUrlParam($link, 'text', '{message}');
50
        }
51
52
        return $link;
53
    }
54
}
55