SocialShare   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 32
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 6 2
A run() 0 14 2
1
<?php
2
3
namespace hiqdev\themes\obaju\widgets;
4
5
use Yii;
6
use yii\base\Widget;
7
use yii\helpers\Html;
8
9
class SocialShare extends Widget
10
{
11
    public $shareLink;
12
13
    protected $socials = [
14
        'facebook|facebook' => 'https://www.facebook.com/sharer/sharer.php?u=',
15
        'google-plus|gplus' => 'https://twitter.com/home?status=',
16
        'twitter|twitter' => 'https://plus.google.com/share?url=',
17
    ];
18
19
    public function init()
20
    {
21
        if (!$this->shareLink) {
22
            $this->shareLink = Yii::$app->request->absoluteUrl;
23
        }
24
    }
25
26
    public function run()
27
    {
28
        $out = '';
29
        foreach ($this->socials as $item => $url) {
30
            list($icon, $linkClass) = explode('|', $item);
31
            $out .= Html::a("<i class=\"fa fa-{$icon}\"></i>", implode('', [$url, $this->shareLink]), [
32
                'class' => 'external ' . $linkClass,
33
                'style' => 'opacity: 1;',
34
                'data-animate-hover' => 'pulse',
35
            ]);
36
        }
37
38
        return $out;
39
    }
40
}
41