ChangeInfoBox   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 9 3
A run() 0 8 1
1
<?php
2
/**
3
 * Created for IG Monitoring.
4
 * User: jakim <[email protected]>
5
 * Date: 17.02.2018
6
 */
7
8
namespace app\modules\admin\widgets;
9
10
11
use Yii;
12
use yii\base\Widget;
13
14
class ChangeInfoBox extends Widget
15
{
16
    public $header = 'Bookmarks';
17
    public $number = '41';
18
    public $format = 'integer';
19
20
    protected $bgCssClass = 'bg-blue';
21
22
    /**
23
     * @var \app\components\Formatter
24
     */
25
    protected $formatter;
26
27
    public function init()
28
    {
29
        $this->formatter = Yii::$app->formatter;
0 ignored issues
show
Documentation Bug introduced by
Yii::app->formatter is of type yii\i18n\Formatter, but the property $formatter was declared to be of type app\components\Formatter. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
30
        parent::init();
31
        $this->number = $this->formatter->asChange($this->number, false, $this->format);
32
        if ($this->number > 0) {
33
            $this->bgCssClass = 'bg-green';
34
        } elseif ($this->number < 0) {
35
            $this->bgCssClass = 'bg-red';
36
        }
37
    }
38
39
    public function run()
40
    {
41
        echo "<div class=\"small-box {$this->bgCssClass}\">";
42
        echo "<div class=\"inner\">";
43
        echo "<span class=\"info-box-text\">{$this->header}</span>";
44
        echo "<span class=\"info-box-number\">{$this->number}</span>";
45
        echo "</div>";
46
        echo "</div>";
47
    }
48
}