HubSellForm::tableName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
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