Passed
Push — master ( eb4b1c...eb14df )
by Paweł
03:02
created

InvalidAccountAlert   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 10 3
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\AccountInvalidationType;
12
use yii\base\Widget;
13
use yii\helpers\ArrayHelper;
14
15
class InvalidAccountAlert extends Widget
16
{
17
    /**
18
     * @var \app\models\Account
19
     */
20
    public $model;
21
22
    public function run()
23
    {
24
        $icon = $this->model->invalidation_type_id == AccountInvalidationType::IS_PRIVATE ? 'user-secret' : 'exclamation-triangle';
25
        $alert = $this->model->invalidation_count < 3 ? 'warning' : 'danger';
26
27
        return $this->render('invalid-alert', [
28
            'alert' => $alert,
29
            'icon' => $icon,
30
            'header' => 'Invalid account',
31
            'lines' => $this->lines(),
32
        ]);
33
    }
34
35
    protected function lines()
36
    {
37
        $formatter = \Yii::$app->formatter;
38
39
        return [
40
            sprintf('type: %s', ArrayHelper::getValue(AccountInvalidationType::labels(), $this->model->invalidation_type_id, 'Unknown reason')),
41
            sprintf('attempts: %s', $formatter->asInteger($this->model->invalidation_count)),
42
            sprintf('next try: %s', $formatter->asDatetime($this->model->update_stats_after)),
43
        ];
44
    }
45
46
}