Completed
Pull Request — master (#271)
by
unknown
03:12
created

EntriesList   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 7 1
A getEntries() 0 4 1
A get() 0 4 1
A populate() 0 18 1
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 entries.
24
     * 
25
     * @return array
26
     */
27
    public function getEntries()
28
    {
29
        return $this->getIfSet('entries');
30
    }
31
32
    /**
33
     * Get a entries list.
34
     * 
35
     * @return stdClass
36
     */
37
    public function get()
38
    {
39
        return $this->getByPath(sprintf('/%s/%s', MoipResource::VERSION, self::PATH), [], true);
40
    }
41
42
    protected function populate(stdClass $response)
43
    {
44
        $entriesList = clone $this;
45
46
        $entriesList->data->summary->amount = $response->summary->amount;
47
        
48
        $entriesList->data->summary->count = $response->summary->count;
49
50
        $entriesList->data->_links->previous = new stdClass();
51
        $entriesList->data->_links->previous->href = $response->_links->previous->href;
52
53
        $entriesList->data->_links->next = new stdClass();
54
        $entriesList->data->_links->next->href = $response->_links->next->href;
55
56
        $entriesList->data->entries = $response->entries;
57
58
        return $entriesList;
59
    }
60
}
61