HubSellForm   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 2
b 0
f 0
dl 0
loc 33
ccs 0
cts 15
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A tableName() 0 3 1
A fromHub() 0 3 1
A rules() 0 7 1
1
<?php
2
/**
3
 * Server module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-server
6
 * @package   hipanel-module-server
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\server\forms;
12
13
use hipanel\modules\server\models\Hub;
14
15
class HubSellForm extends Hub
16
{
17
    use \hipanel\base\ModelTrait;
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public static function tableName()
23
    {
24
        return 'hub';
25
    }
26
27
    /**
28
     * Create HubSellForm model from Hub model.
29
     *
30
     * @param Hub $hub
31
     * @return HubSellForm
32
     */
33
    public static function fromHub(Hub $hub): HubSellForm
34
    {
35
        return new self(array_merge($hub->getAttributes(), ['scenario' => 'sell']));
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function rules()
42
    {
43
        return array_merge(parent::rules(), [
44
            [['client_id', 'tariff_id', 'sale_time'], 'required'],
45
            [['id', 'client_id', 'tariff_id'], 'integer', 'on' => 'sell'],
46
            [['sale_time'], 'date', 'format'  => 'php:Y-m-d H:i:s', 'on' => 'sell'],
47
            [['move_accounts'], 'boolean', 'on' => ['sell']],
48
        ]);
49
    }
50
}
51