InvalidTagAlert   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 11 2
A lines() 0 8 1
1
<?php
2
/**
3
 * Created for IG Monitoring.
4
 * User: jakim <[email protected]>
5
 * Date: 06.09.2018
6
 */
7
8
namespace app\modules\admin\widgets;
9
10
11
use app\dictionaries\TagInvalidationType;
12
use Yii;
13
use yii\base\Widget;
14
use yii\helpers\ArrayHelper;
15
16
class InvalidTagAlert extends Widget
17
{
18
    /**
19
     * @var \app\models\Tag
20
     */
21
    public $model;
22
23
    public function run()
24
    {
25
        $icon = 'exclamation-triangle';
26
        $alert = $this->model->invalidation_count < 3 ? 'warning' : 'danger';
27
28
        return $this->render('invalid-alert', [
29
            'alert' => $alert,
30
            'icon' => $icon,
31
            'header' => 'Invalid tag',
32
            'lines' => $this->lines(),
33
            'updateUrl' => ['tag/force-update', 'id' => $this->model->id],
34
        ]);
35
    }
36
37
    protected function lines()
38
    {
39
        $formatter = Yii::$app->formatter;
40
41
        return [
42
            sprintf('type: %s', ArrayHelper::getValue(TagInvalidationType::labels(), $this->model->invalidation_type_id, 'Unknown reason')),
43
            sprintf('attempts: %s', $formatter->asInteger($this->model->invalidation_count)),
44
            sprintf('next try: %s', $formatter->asDatetime($this->model->update_stats_after)),
45
        ];
46
    }
47
48
}