Completed
Pull Request — master (#133)
by
unknown
01:41
created

Escrow::populate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 1
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Moip\Resource;
4
5
use stdClass;
6
use Requests;
7
8
/**
9
 * Class Escrow.
10
 */
11
class Escrow extends MoipResource {
12
    
13
    /**
14
     * @const string
15
     */
16
    const PATH = 'escrows';
17
    
18
    /**
19
     * Initializes new instances.
20
     */
21
    protected function initialize()
22
    {
23
        $this->data = new stdClass();
24
    }
25
    
26
    /**
27
     * Set id MoIP escrow.
28
     *
29
     *
30
     * @return \Moip\Resource\Escrow
31
     */
32
    public function setId($id)
33
    {
34
        $this->data->id = $id;
35
36
        return $this;
37
    }
38
    
39
    /**
40
     * Get id MoIP escrow.
41
     *
42
     *
43
     * @return \Moip\Resource\Escrow
44
     */
45
    public function getId()
46
    {
47
        return $this->getIfSet('id');
48
    }
49
    
50
    /**
51
     * Get escrow status.
52
     *
53
     * @return string Escrow status. Possible values HOLD_PENDING, HELD, RELEASED
54
     */
55
    public function getStatus()
56
    {
57
        return $this->getIfSet('status');
58
    }
59
60
    /**
61
     * get creation time.
62
     *
63
     * @return \DateTime
64
     */
65
    public function getCreatedAt()
66
    {
67
        return $this->data->createdAt;
68
    }
69
70
    /**
71
     * Returns when the last update occurred.
72
     *
73
     * @return \DateTime
74
     */
75
    public function getUpdatedAt()
76
    {
77
        return $this->data->updatedAt;
78
    }
79
    
80
    /**
81
     * Get escrow description
82
     *
83
     * @return string Escrow description
84
     */
85
    public function getDescription()
86
    {
87
        return $this->data->description;
88
    }
89
    
90
    /**
91
     * Release a escrow payment
92
     *
93
     * @return Payment
94
     */
95
    
96 View Code Duplication
    public function release() 
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
97
    {
98
        $path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, self::PATH, $this->getId(), 'release');
99
100
        $response = $this->httpRequest($path, Requests::POST, []);
101
102
        return $this->populate($response);
103
    }
104
    
105
    /**
106
     * Mount escrow structure.
107
     *
108
     * @param \stdClass $response
109
     *
110
     * @return Escrow
111
     */
112
    protected function populate(stdClass $response)
113
    {
114
        $escrow = clone $this;
115
116
        $escrow->data->id = $this->getIfSet('id', $response);
117
        $escrow->data->status = $this->getIfSet('status', $response);
118
        $escrow->data->description = $this->getIfSet('description', $response);
119
        $escrow->data->amount = $this->getIfSet('amount', $response);
120
        $escrow->data->_links = $this->getIfSet('_links', $response);
121
        $escrow->data->createdAt = $this->getIfSetDateTime('createdAt', $response);
122
        $escrow->data->updatedAt = $this->getIfSetDateTime('updatedAt', $response);
123
124
        return $escrow;
125
    }
126
}
127