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

ActionDto::load()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 10
nc 4
nop 2
crap 12
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