Twitter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 38
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A autoLinkTweet() 0 25 3
1
<?php
2
/**
3
 * @link      https://dukt.net/twitter/
4
 * @copyright Copyright (c) Dukt
5
 * @license   https://github.com/dukt/twitter/blob/master/LICENSE.md
6
 */
7
8
namespace dukt\twitter\services;
9
10
use dukt\twitter\lib\AutoLink;
11
use yii\base\Component;
12
13
/**
14
 * Twitter Service
15
 *
16
 * @author Dukt <[email protected]>
17
 * @since  3.0
18
 */
19
class Twitter extends Component
20
{
21
    // Public Methods
22
    // =========================================================================
23
24
    /**
25
     * Returns the tweet with URLs transformed into HTML links
26
     *
27
     * @param int   $text    The tweet's text.
28
     * @param array $options Options to pass to AutoLink.
29
     *
30
     * @return string
31
     */
32
    public function autoLinkTweet($text, $options = [])
33
    {
34
        $twitter = AutoLink::create();
35
36
        $aliases = [
37
            'urlClass' => 'setURLClass',
38
            'usernameClass' => 'setUsernameClass',
39
            'listClass' => 'setListClass',
40
            'hashtagClass' => 'setHashtagClass',
41
            'cashtagClass' => 'setCashtagClass',
42
            'noFollow' => 'setNoFollow',
43
            'external' => 'setExternal',
44
            'target' => 'setTarget',
45
            'noOpener' => 'setNoOpener'
46
        ];
47
48
        foreach ($options as $k => $v) {
49
            if (isset($aliases[$k])) {
50
                $twitter->{$aliases[$k]}($v);
51
            }
52
        }
53
54
        $html = $twitter->autoLink($text);
55
56
        return $html;
57
    }
58
}
59