CurrencyExchangeForm   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
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 46
ccs 0
cts 18
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 12 2
1
<?php
2
/**
3
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\forms;
12
13
use hipanel\base\Model;
14
use hipanel\modules\finance\models\Bill;
15
use hiqdev\hiart\ResponseErrorException;
16
17
class CurrencyExchangeForm extends Model
18
{
19
    /**
20
     * @var int
21
     */
22
    public $client_id;
23
24
    /**
25
     * @var string source currency
26
     */
27
    public $from;
28
29
    /**
30
     * @var string target currency
31
     */
32
    public $to;
33
34
    /**
35
     * @var float original sum to be exchanged
36
     */
37
    public $sum;
38
39
    public $result;
40
41
    public function rules()
42
    {
43
        return [
44
            [['client_id', 'from', 'to', 'sum'], 'required'],
45
            [['sum'], 'double'],
46
            [['from', 'to'], 'string', 'length' => 3],
47
        ];
48
    }
49
50
    public function save($runValidation = true, $attributeNames = null)
51
    {
52
        try {
53
            $result = Bill::perform('create-exchange', $this->getAttributes());
54
        } catch (ResponseErrorException $e) {
55
            $this->addError('client_id', $e->getMessage());
56
57
            return false;
58
        }
59
60
        return $result['id'];
61
    }
62
}
63