Completed
Push — master ( 76d596...34b53d )
by Dmitry
04:27
created

CurrencyExchangeForm   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 45
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 8 1
A save() 0 11 2
1
<?php
2
3
namespace hipanel\modules\finance\forms;
4
5
use hipanel\base\Model;
6
use hipanel\modules\finance\models\Bill;
7
use hiqdev\hiart\ResponseErrorException;
8
9
class CurrencyExchangeForm extends Model
10
{
11
    /**
12
     * @var int
13
     */
14
    public $client_id;
15
16
    /**
17
     * @var string source currency
18
     */
19
    public $from;
20
21
    /**
22
     * @var string target currency
23
     */
24
    public $to;
25
26
    /**
27
     * @var float original sum to be exchanged
28
     */
29
    public $sum;
30
31
    public $result;
32
33
    public function rules()
34
    {
35
        return [
36
            [['client_id', 'from', 'to', 'sum'], 'required'],
37
            [['sum'], 'double'],
38
            [['from', 'to'], 'string', 'length' => 3]
39
        ];
40
    }
41
42
    public function save($runValidation = true, $attributeNames = null)
43
    {
44
        try {
45
            $result = Bill::perform('create-exchange', $this->getAttributes());
46
        } catch (ResponseErrorException $e) {
47
            $this->addError('client_id', $e->getMessage());
48
            return false;
49
        }
50
51
        return $result['id'];
52
    }
53
}
54