Service   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 48
ccs 0
cts 38
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 21 1
A attributeLabels() 0 9 1
A getIps() 0 4 1
A getPageTitle() 0 4 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 hipanel\base\Model;
14
use hipanel\base\ModelTrait;
15
use hipanel\helpers\StringHelper;
16
use Yii;
17
18
class Service extends Model
19
{
20
    use ModelTrait;
21
22
    /** {@inheritdoc} */
23
    public function rules()
24
    {
25
        return [
26
            [['id', 'server_id', 'device_id', 'client_id', 'seller_id', 'soft_id'], 'integer'],
27
            [['name', 'server', 'device', 'client', 'seller', 'soft'], 'safe'],
28
            [['ip', 'ips', 'bin', 'etc', 'objects_count'], 'safe'],
29
            [['soft_type', 'soft_type_label', 'state', 'state_label'], 'safe'],
30
            [['server'], 'safe', 'on' => ['create']],
31
            [['bin', 'etc', 'soft', 'state'], 'safe', 'on' => ['create', 'update']],
32
            [['ips'], 'filter',
33
                'filter' => function ($value) {
34
                    return StringHelper::explode($value);
35
                },
36
                'skipOnArray' => true, 'on' => ['create', 'update'],
37
            ],
38
            [['ips'], 'each', 'rule' => ['ip'], 'on' => ['create', 'update']],
39
            [['server', 'name', 'etc', 'bin', 'soft', 'state', 'ips'], 'required', 'on' => ['create', 'update']],
40
            [['id', 'server'], 'required', 'on' => ['update']],
41
            [['id'], 'required', 'on' => ['update']],
42
        ];
43
    }
44
45
    /** {@inheritdoc} */
46
    public function attributeLabels()
47
    {
48
        return $this->mergeAttributeLabels([
49
            'soft_type'         => Yii::t('hipanel', 'Type'),
50
            'bin'               => Yii::t('hipanel:hosting', 'bin'),
51
            'etc'               => Yii::t('hipanel:hosting', 'etc'),
52
            'soft'              => Yii::t('hipanel:hosting', 'Soft'),
53
        ]);
54
    }
55
56
    public function getIps()
57
    {
58
        return $this->hasMany(Ip::class, ['service_id', 'id']);
59
    }
60
61
    public function getPageTitle()
62
    {
63
        return implode(': ', array_filter([$this->server, $this->name]));
0 ignored issues
show
Documentation introduced by
The property server does not exist on object<hipanel\modules\hosting\models\Service>. 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...
Documentation introduced by
The property name does not exist on object<hipanel\modules\hosting\models\Service>. 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...
64
    }
65
}
66