Db   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 56
ccs 0
cts 45
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 31 1
A attributeLabels() 0 8 1
A scenarioActions() 0 8 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\modules\hosting\validators\DbNameValidator;
16
use Yii;
17
18
class Db extends Model
19
{
20
    use ModelTrait;
21
22
    /** {@inheritdoc} */
23
    public function rules()
24
    {
25
        return [
26
            [['id', 'account_id', 'client_id', 'seller_id', 'service_id', 'device_id', 'server_id'], 'integer'],
27
            [['name', 'account', 'client', 'seller', 'service', 'device', 'server'], 'safe'],
28
            [['service_ip', 'description'], 'safe'],
29
            [['type', 'state', 'backuping_type', 'type_label', 'state_label', 'backuping_type_label'], 'safe'],
30
            /// Create
31
            [['server', 'account', 'service_id', 'name', 'password'], 'required', 'on' => ['create']],
32
            [['name'], DbNameValidator::class, 'on' => ['create']],
33
            [['password'], 'string', 'min' => 8, 'max' => 20, 'on' => ['create', 'set-password']],
34
            [
35
                ['password'],
36
                'match',
37
                'pattern' => '/^([A-Za-z0-9!@#$%^&*()\-_=+{};:,<.>]{8,20})$/', // old version '/^[\x20-\x7f]*$/'
38
                'message' => Yii::t('hipanel:hosting', '{attribute} should not contain non-latin characters'),
39
                'on'      => ['create', 'set-password'],
40
            ],
41
            [
42
                ['password'],
43
                'match',
44
                'pattern' => '/(?=(?:.*[!@#$%^&*()\-_=+{};:,<.>]){1,})/',
45
                'message' => Yii::t('hipanel:hosting', '{attribute} should contain at least one special character'),
46
                'on' => ['create', 'set-password'],
47
            ],
48
            [['password'], 'required', 'on' => ['set-password']],
49
            [['id'], 'required', 'on' => ['delete', 'set-password', 'set-description', 'truncate']],
50
            [['backuping_exists'], 'boolean'],
51
            [['backuping_type'], 'required', 'on' => ['enable-backuping', 'disable-backuping']],
52
        ];
53
    }
54
55
    /** {@inheritdoc} */
56
    public function attributeLabels()
57
    {
58
        return $this->mergeAttributeLabels([
59
            'name'                 => Yii::t('hipanel:hosting', 'DB name'),
60
            'service_ip'           => Yii::t('hipanel:hosting', 'Service IP'),
61
            'backuping_type'       => Yii::t('hipanel:hosting', 'Backup type'),
62
        ]);
63
    }
64
65
    public function scenarioActions()
66
    {
67
        $result = [];
68
        $result['enable-backuping'] = 'update-backuping';
69
        $result['disable-backuping'] = 'update-backuping';
70
71
        return $result;
72
    }
73
}
74