Link   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 25
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A tableName() 0 4 1
A rules() 0 15 1
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\models;
12
13
use yii\web\JsExpression;
14
15
class Link extends \hipanel\base\Model
16
{
17
    use \hipanel\base\ModelTrait;
18
19
    public static function tableName()
20
    {
21
        return 'ip';
22
    }
23
24
    public function rules()
25
    {
26
        return [
27
            [['id', 'ip_id', 'device_id', 'service_id', 'soft_id'], 'integer'],
28
            [['ip', 'service', 'soft', 'soft_type', 'soft_type_label', 'device_ptype'], 'safe'],
29
            [['device'], 'safe', 'on' => ['create', 'update']],
30
            [['service_id', 'ip_id', 'id'], 'integer', 'on' => ['create', 'update']],
31
            [['id'], 'required', 'on' => ['delete']],
32
            [['service_id'], 'required', 'when' => function ($model) {
0 ignored issues
show
Unused Code introduced by
The parameter $model is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
33
                return !empty($this->server);
0 ignored issues
show
Documentation introduced by
The property server does not exist on object<hipanel\modules\hosting\models\Link>. 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...
34
            }, 'whenClient' => new JsExpression("function (attribute, value) {
35
                return $(attribute).parent('.item').find('[data-attribute=server]').val();
36
            }"), 'on' => ['create', 'update']],
37
        ];
38
    }
39
}
40