Completed
Pull Request — master (#255)
by
unknown
02:23
created

Balances::populate()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 8
nop 1
dl 0
loc 9
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace Moip\Resource;
4
5
use stdClass;
6
7
/**
8
 * Class Balances.
9
 */
10
class Balances extends MoipResource
11
{
12
    /**
13
     * Path balances API.
14
     *
15
     * @const string
16
     */
17
    const PATH = 'balances';
18
19
    /**
20
     * Initialize a new instance.
21
     */
22
    public function initialize()
23
    {
24
        $this->data = new stdClass();
25
        $this->data->unavailable = [];
26
        $this->data->future = [];
27
        $this->data->current = [];
28
    }
29
30
    /**
31
     * Populate this instance.
32
     *
33
     * @param stdClass $response response object
34
     *
35
     * @return mixed|Balances
36
     */
37
    protected function populate(stdClass $response)
38
    {
39
        $balances = clone $this;
40
        $balances->data->unavailable = $this->getIfSet('unavailable', $response) ?: [];
41
        $balances->data->future = $this->getIfSet('future', $response) ?: [];
42
        $balances->data->current = $this->getIfSet('current', $response) ?: [];
43
44
        return $balances;
45
    }
46
47
    /**
48
     * Get all balances.
49
     *
50
     * @return stdClass
51
     */
52
    public function get()
53
    {
54
        $path = sprintf('/%s/%s', MoipResource::VERSION, self::PATH);
55
56
        return $this->getByPath($path, ['Accept' => static::ACCEPT_VERSION]);
57
    }
58
59
    /**
60
     * Get unavailable balances. Returns an array of objects with the amount and currency.
61
     *
62
     * @return array
63
     */
64
    public function getUnavailable()
65
    {
66
        return $this->data->unavailable;
67
    }
68
69
    /**
70
     * Get future balances. Returns an array of objects with the amount and currency.
71
     *
72
     * @return array
73
     */
74
    public function getFuture()
75
    {
76
        return $this->data->future;
77
    }
78
79
    /**
80
     * Get current balances. Returns an array of objects with the amount and currency.
81
     *
82
     * @return array
83
     */
84
    public function getCurrent()
85
    {
86
        return $this->data->current;
87
    }
88
}
89