ExchangeBuilder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 82
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A reference() 0 3 1
A to() 0 3 1
A setAccount() 0 12 2
A from() 0 3 1
1
<?php
2
3
namespace tbclla\Revolut\Builders;
4
5
class ExchangeBuilder extends Builder
6
{
7
    /**
8
     * Information about the account you want to exchange from
9
     *
10
     * @var array
11
     */
12
    public $from;
13
14
    /**
15
     * Information about the account you want to exchange to
16
     *
17
     * @var array
18
     */
19
    public $to;
20
21
22
    /**
23
     * An optional reference
24
     *
25
     * @var string
26
     */
27
    public $reference;
28
29
    /**
30
     * Set the outgoing account
31
     *
32
     * @param string $accountId the account ID
33
     * @param string $currency the account currency
34
     * @param float $amount the amount of currency to sell (only when selling)
35
     * @return self
36
     */
37
    public function from(string $accountId, string $currency, float $amount = null)
38
    {
39
        return $this->setAccount('from', $accountId, $currency, $amount);
40
    }
41
42
    /**
43
     * Set the receiving account
44
     *
45
     * @param string $accountId the account ID
46
     * @param string $currency the account currency
47
     * @param float $amount	the amount of currency to buy (only when buying)
48
     * @return self
49
     */
50
    public function to(string $accountId, string $currency, float $amount = null)
51
    {
52
        return $this->setAccount('to', $accountId, $currency, $amount);
53
    }
54
55
    /**
56
     * Set an optional reference
57
     *
58
     * @param string $reference
59
     * @return self
60
     */
61
    public function reference(string $reference)
62
    {
63
        return $this->setAttribute('reference', $reference);
64
    }
65
66
    /**
67
     * Set the account information
68
     *
69
     * @param string $type
70
     * @param string $accountId
71
     * @param string $currency
72
     * @param float $amount
73
     * @return self
74
     */
75
    private function setAccount(string $type, string $accountId, string $currency, $amount)
76
    {
77
        $account = [
78
            'account_id' => $accountId,
79
            'currency' => $currency,
80
        ];
81
82
        if ($amount) {
83
            $account['amount'] = $amount;
84
        }
85
86
        return $this->setAttribute($type, $account);
87
    }
88
}
89