Completed
Push — master ( 82fec5...d103b3 )
by Andrii
13:09
created

Service::getPageTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\hosting\models;
12
13
use hipanel\helpers\StringHelper;
14
use Yii;
15
16
class Service extends \hipanel\base\Model
17
{
18
    use \hipanel\base\ModelTrait;
19
20
    /** {@inheritdoc} */
21
    public function rules()
22
    {
23
        return [
24
            [['id', 'server_id', 'device_id', 'client_id', 'seller_id', 'soft_id'], 'integer'],
25
            [['name', 'server', 'device', 'client', 'seller', 'soft'], 'safe'],
26
            [['ip', 'ips', 'bin', 'etc', 'objects_count'], 'safe'],
27
            [['soft_type', 'soft_type_label', 'state', 'state_label'], 'safe'],
28
            [['server'], 'safe', 'on' => ['create']],
29
            [['bin', 'etc', 'soft', 'state'], 'safe', 'on' => ['create', 'update']],
30
            [['ips'], 'filter',
31
                'filter' => function ($value) {
32
                    return StringHelper::explode($value);
33
                },
34
                'skipOnArray' => true, 'on' => ['create', 'update'],
35
            ],
36
            [['ips'], 'each', 'rule' => ['ip'], 'on' => ['create', 'update']],
37
            [['server', 'name'], 'required', 'on' => ['create']],
38
            [['id', 'server'], 'required', 'on' => ['update']],
39
            [['id'], 'required', 'on' => ['update']],
40
        ];
41
    }
42
43
    /** {@inheritdoc} */
44
    public function attributeLabels()
45
    {
46
        return $this->mergeAttributeLabels([
47
            'soft_type'         => Yii::t('hipanel', 'Type'),
48
            'bin'               => Yii::t('hipanel:hosting', 'bin'),
49
            'etc'               => Yii::t('hipanel:hosting', 'etc'),
50
            'soft'              => Yii::t('hipanel:hosting', 'Soft'),
51
        ]);
52
    }
53
54
    public function getIps()
55
    {
56
        return $this->hasMany(Ip::class, ['service_id', 'id']);
57
    }
58
59
    public function getPageTitle()
60
    {
61
        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...
62
    }
63
}
64