Completed
Pull Request — master (#273)
by
unknown
09:57
created

EntriesList::getSummary()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Moip\Resource;
4
5
use stdClass;
6
7
class EntriesList extends MoipResource
8
{
9
    /**
10
     * @const string
11
     */
12
    const PATH = 'entries';
13
14
    public function initialize()
15
    {
16
        $this->data = new stdClass();
17
        $this->data->summary = new stdClass();
18
        $this->data->_links = new stdClass();
19
        $this->data->entries = [];
20
    }
21
22
    /**
23
     * Get summary.
24
     *
25
     * @return stdClass
26
     */
27
    public function getSummary()
28
    {
29
        return $this->getIfSet('summary');
30
    }
31
32
    /**
33
     * Get _links.
34
     *
35
     * @return stdClass
36
     */
37
    public function getLinks()
38
    {
39
        return $this->getIfSet('_links');
40
    }
41
42
    /**
43
     * Get entries.
44
     *
45
     * @return array
46
     */
47
    public function getEntries()
48
    {
49
        return $this->getIfSet('entries');
50
    }
51
52
    /**
53
     * Get a entries list.
54
     *
55
     * @return stdClass
56
     */
57
    public function get()
58
    {
59
        $path = sprintf('/%s/%s', MoipResource::VERSION, self::PATH);
60
61
        return $this->getByPath($path, ['Accept' => static::ACCEPT_VERSION]);
62
    }
63
64
    protected function populate(stdClass $response)
65
    {
66
        $entriesList = clone $this;
67
68
        $entriesList->data->summary->amount = $response->summary->amount;
69
70
        $entriesList->data->summary->count = $response->summary->count;
71
72
        $entriesList->data->_links->previous = new stdClass();
73
        $entriesList->data->_links->previous->href = $response->_links->previous->href;
74
75
        $entriesList->data->_links->next = new stdClass();
76
        $entriesList->data->_links->next->href = $response->_links->next->href;
77
78
        $entriesList->data->entries = $response->entries;
79
80
        return $entriesList;
81
    }
82
}
83