Completed
Push — master ( 22cb37...1cdde8 )
by Dmitry
02:19
created

ActionDto::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
crap 2
1
<?php
2
3
namespace hiqdev\billing\hiapi\commands\order;
4
5
use hiapi\validators\NestedModelValidator;
6
use yii\base\Model;
7
8
class ActionDto extends Model
9
{
10
    public $type;
11
12
    public $target;
13
14
    public $quantity;
15
16
    public function load($data, $formName = '')
17
    {
18
        if (isset($data['quantity'])) {
19
            $quantity = new QuantityDto();
20
            $quantity->load($data['quantity']);
21
22
            $data['quantity'] = $quantity;
23
        }
24
25
        if (isset($data['target'])) {
26
            $target = new TargetDto();
27
            $target->load($data['target']);
28
29
            $data['target'] = $target;
30
        }
31
32
        return $this->setAttributes($data);
33
    }
34
35
    public function rules()
36
    {
37
        return [
38
            [['type', 'target', 'quantity'], 'required'],
39
            [['target', 'quantity'], NestedModelValidator::class],
40
            [['type'], 'string']
41
        ];
42
    }
43
}
44