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

QuantityDto   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 32
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 9 1
A unitValidation() 0 10 2
A load() 0 4 1
1
<?php
2
3
namespace hiqdev\billing\hiapi\commands\order;
4
5
use hiqdev\php\units\Quantity;
6
use yii\base\Model;
7
8
class QuantityDto extends Model
9
{
10
    public $unit;
11
12
    public $quantity;
13
14
    public function rules()
15
    {
16
        return [
17
            [['unit', 'quantity'], 'required'],
18
            ['unit', 'string'],
19
            ['quantity', 'number'],
20
            ['unit', 'unitValidation']
21
        ];
22
    }
23
24
    public function unitValidation()
25
    {
26
        try {
27
            Quantity::create($this->unit, $this->quantity);
28
            return true;
29
        } catch (\Exception $exception) {
30
            $this->addError('unit', $exception->getMessage());
31
            return false;
32
        }
33
    }
34
35
    public function load($data, $formName = '')
36
    {
37
        return parent::load($data, $formName);
38
    }
39
}
40