Completed
Push — master ( 823023...c43f27 )
by Dmitry
06:01 queued 02:13
created

HubSellForm::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace hipanel\modules\server\forms;
4
5
use hipanel\modules\server\models\Hub;
6
7
class HubSellForm extends Hub
8
{
9
    use \hipanel\base\ModelTrait;
10
11
    /**
12
     * @inheritdoc
13
     */
14
    public static function tableName()
15
    {
16
        return 'hub';
17
    }
18
19
    /**
20
     * Create HubSellForm model from Hub model
21
     *
22
     * @param Hub $hub
23
     * @return HubSellForm
24
     */
25
    public static function fromHub(Hub $hub): HubSellForm
26
    {
27
        return new self(array_merge($hub->getAttributes(), ['scenario' => 'sell']));
28
    }
29
30
    /**
31
     * @inheritdoc
32
     */
33
    public function rules()
34
    {
35
        return array_merge(parent::rules(), [
36
            [['client_id', 'tariff_id', 'sale_time'], 'required'],
37
            [['id', 'client_id', 'tariff_id'], 'integer', 'on' => 'sell'],
38
            [['sale_time'], 'date', 'format'  => 'php:Y-m-d H:i:s', 'on' => 'sell'],
39
            [['move_accounts'], 'boolean', 'on' => ['sell']],
40
        ]);
41
    }
42
}
43
44