Completed
Push — master ( 0c8dab...807ddc )
by Dmitry
04:39
created

Expires::init()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 22
ccs 0
cts 19
cp 0
rs 8.6737
cc 5
eloc 15
nc 5
nop 0
crap 30
1
<?php
2
/**
3
 * Server module for HiPanel.
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-server
6
 * @package   hipanel-module-server
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
/**
12
 * @see    http://hiqdev.com/hipanel-module-domain
13
 * @license http://hiqdev.com/hipanel-module-domain/license
14
 * @copyright Copyright (c) 2015 HiQDev
15
 */
16
17
namespace hipanel\modules\server\widgets;
18
19
use hipanel\modules\server\models\Server;
20
use Yii;
21
22
class Expires extends \hipanel\widgets\Label
23
{
24
    /**
25
     * @var Server
26
     */
27
    public $model;
28
29
    public function init()
30
    {
31
        $expires = $this->model->expires;
0 ignored issues
show
Documentation introduced by
The property expires does not exist on object<hipanel\modules\server\models\Server>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
32
        $this->label = Yii::t('hipanel:server', '(not sold)');
0 ignored issues
show
Bug introduced by
The property label does not seem to exist. Did you mean _label?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
33
34
        if (!empty($expires)) {
35
            if (strtotime($expires) < time()) {
36
                $class = 'danger';
37
            } elseif (strtotime($expires) < strtotime('+5 days', time())) {
38
                $class = 'warning';
39
            } elseif (strtotime($expires) < strtotime('+30 days', time())) {
40
                $class = 'info';
41
            } else {
42
                $class = 'default';
43
            }
44
45
            $this->color = $class;
0 ignored issues
show
Bug introduced by
The property color does not seem to exist. Did you mean _color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
46
            $this->label = Yii::$app->formatter->asDate($expires);
0 ignored issues
show
Bug introduced by
The property label does not seem to exist. Did you mean _label?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
47
        }
48
49
        parent::init();
50
    }
51
}
52