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

CalculateValueCommand::load()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 2
nop 2
crap 12
1
<?php
2
3
namespace hiqdev\billing\hiapi\commands\order;
4
5
use hiapi\commands\BaseCommand;
6
use hiapi\validators\NestedModelValidator;
7
8
class CalculateValueCommand extends BaseCommand
9
{
10
    public $items;
11
12
    public function load($data, $formName = '')
13
    {
14
        if (isset($data['items'])) {
15
            $items = [];
16
            foreach ($data['items'] as $item) {
17
                $items[] = $action = new ActionDto();
18
                $action->load($item);
19
            }
20
            $data['items'] = $items;
21
        }
22
23
        return $this->setAttributes($data);
24
    }
25
26
    public function rules()
27
    {
28
        return [
29
            ['items', 'required'],
30
            ['items', 'each', 'rule' => [NestedModelValidator::class]],
31
        ];
32
    }
33
}
34