SocialShare::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 12
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 0
crap 6
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