Type   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 50
ccs 0
cts 31
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 25 3
A renderLabel() 0 8 2
1
<?php
2
/**
3
 * Hosting Plugin for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-hosting
6
 * @package   hipanel-module-hosting
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\hosting\widgets\mail;
12
13
use hipanel\modules\hosting\models\Mail;
14
use hipanel\widgets\Label;
15
use Yii;
16
17
class Type extends Label
18
{
19
    /**
20
     * @var Mail
21
     */
22
    public $model;
23
24
    public $default = null;
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function init()
30
    {
31
        $model = $this->model;
32
        if ($model->type === $model::TYPE_FORWARD_ONLY) {
0 ignored issues
show
Documentation introduced by
The property type does not exist on object<hipanel\modules\hosting\models\Mail>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
33
            $this->label = Yii::t('hipanel:hosting', 'Forward only');
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...
34
            $this->color = 'primary';
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...
35
            $this->labelOptions = [
36
                'title' => Yii::t('hipanel:hosting', 'You can not login to this mailbox, but all messages will be forwarded to specified addresses'),
37
            ];
38
        } elseif ($model->type === $model::TYPE_BOX_WITH_FORWARDS) {
0 ignored issues
show
Documentation introduced by
The property type does not exist on object<hipanel\modules\hosting\models\Mail>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
39
            $this->label = Yii::t('hipanel:hosting', 'Mailbox with forwards');
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...
40
            $this->color = 'warning';
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...
41
            $this->labelOptions = [
42
                'title' => Yii::t('hipanel:hosting', 'You can login this mailbox, also all the messages will be forwarded to specified addresses'),
43
            ];
44
        } else {
45
            $this->label = Yii::t('hipanel:hosting', 'Mailbox');
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...
46
            $this->color = 'default';
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...
47
            $this->labelOptions = [
48
                'title' => Yii::t('hipanel:hosting', 'You can login this mailbox'),
49
            ];
50
        }
51
52
        parent::init();
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    protected function renderLabel()
59
    {
60
        if ($this->color === null) {
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...
61
            return;
62
        }
63
64
        return parent::renderLabel();
65
    }
66
}
67