InsightsWidget   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 11
Bugs 0 Features 0
Metric Value
eloc 9
c 11
b 0
f 0
dl 0
loc 36
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A displayName() 0 3 1
A getBodyHtml() 0 12 3
A icon() 0 3 1
1
<?php
2
namespace dukt\facebook\widgets;
3
4
use Craft;
5
use dukt\facebook\Plugin as Facebook;
6
use dukt\facebook\web\assets\insightswidget\InsightsWidgetAsset;
7
8
/**
9
 * InsightsWidget represents an Insights dashboard widget.
10
 *
11
 * @author Dukt <[email protected]>
12
 * @since  2.0
13
 */
14
class InsightsWidget extends \craft\base\Widget
15
{
16
    // Public Methods
17
    // =========================================================================
18
19
    /**
20
     * @inheritdoc
21
     */
22
    public static function displayName(): string
23
    {
24
        return Craft::t('facebook', 'Facebook Insights');
25
    }
26
27
    /**
28
     * @inheritdoc
29
     */
30
    public static function icon()
31
    {
32
        return Craft::getAlias('@dukt/facebook/icons/like.svg');
0 ignored issues
show
Bug Best Practice introduced by
The expression return Craft::getAlias('...cebook/icons/like.svg') also could return the type false which is incompatible with the return type mandated by craft\base\WidgetInterface::icon() of null|string.
Loading history...
33
    }
34
35
    /**
36
     * @inheritdoc
37
     */
38
    public function getBodyHtml()
39
    {
40
        $facebookInsightsObjectId = Facebook::$plugin->getSettings()->facebookInsightsObjectId;
41
42
        if (Facebook::$plugin->isConfigured() && $facebookInsightsObjectId) {
43
            Craft::$app->getView()->registerAssetBundle(InsightsWidgetAsset::class);
44
            Craft::$app->getView()->registerJs('new Craft.FacebookInsightsWidget("widget'.$this->id.'");');
45
46
            return Craft::$app->getView()->renderTemplate('facebook/_components/widgets/Insights/body');
47
        }
48
49
        return Craft::$app->getView()->renderTemplate('facebook/_components/widgets/Insights/not-configured');
50
    }
51
}