Completed
Push — master ( 26e69a...ab0b77 )
by Robin
03:27
created

Statement::setTimestamp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace Kingsquare\Banking;
4
5
/**
6
 * @property array rawData used for debugging purposes
7
 *
8
 * @author Kingsquare ([email protected])
9
 * @license http://opensource.org/licenses/MIT MIT
10
 */
11
class Statement implements \JsonSerializable
12
{
13
    private $bank = '';
14
    private $account = '';
15
    private $transactions = [];
16
    private $startPrice = 0.0;
17
    private $endPrice = 0.0;
18
    private $startTimestamp = 0;
19
    private $endTimestamp = 0;
20
    private $number = '';
21
22
    /**
23
     * @return array
24
     */
25
    public function jsonSerialize()
26
    {
27
        return get_object_vars($this);
28
    }
29
30
    /**
31
     * @param string $var
32
     */
33
    public function setBank($var)
34
    {
35
        $this->bank = (string) $var;
36
    }
37
38
    /**
39
     * @param string $var
40
     */
41
    public function setAccount($var)
42
    {
43
        $this->account = (string) $var;
44
    }
45
46
    /**
47
     * @param Transaction[] $transactions
48
     */
49
    public function setTransactions($transactions)
50
    {
51
        $this->transactions = (array) $transactions;
52
    }
53
54
    /**
55
     * @param float $var
56
     */
57
    public function setStartPrice($var)
58
    {
59
        $this->startPrice = (float) $var;
60
    }
61
62
    /**
63
     * @param float $var
64
     */
65
    public function setEndPrice($var)
66
    {
67
        $this->endPrice = (float) $var;
68
    }
69
70
    /**
71
     * @deprecated
72
     *
73
     * @param int $var
74
     */
75
    public function setTimestamp($var)
76
    {
77
        trigger_error('Deprecated in favor of splitting the start and end timestamps for a statement. '.
78
                'Please use setStartTimestamp($format) or setEndTimestamp($format) instead. '.
79
                'setTimestamp is now setStartTimestamp', E_USER_DEPRECATED);
80
        return $this->setStartTimestamp($var);
81
    }
82
83
    /**
84
     * @param $var
85
     */
86
    public function setStartTimestamp($var)
87
    {
88
        $this->startTimestamp = (int) $var;
89
    }
90
91
    /**
92
     * @param $var
93
     */
94
    public function setEndTimestamp($var)
95
    {
96
        $this->endTimestamp = (int) $var;
97
    }
98
99
    /**
100
     * @param string $var
101
     */
102
    public function setNumber($var)
103
    {
104
        $this->number = (string) $var;
105
    }
106
107
    /**
108
     * @return string
109
     */
110
    public function getBank()
111
    {
112
        return $this->bank;
113
    }
114
115
    /**
116
     * @return string
117
     */
118
    public function getAccount()
119
    {
120
        return $this->account;
121
    }
122
123
    /**
124
     * @return Transaction[]
125
     */
126
    public function getTransactions()
127
    {
128
        return $this->transactions;
129
    }
130
131
    /**
132
     * @return float
133
     */
134
    public function getStartPrice()
135
    {
136
        return $this->startPrice;
137
    }
138
139
    /**
140
     * @return float
141
     */
142
    public function getEndPrice()
143
    {
144
        return $this->endPrice;
145
    }
146
147
    /**
148
     * @param string $format
149
     *
150
     * @deprecated This method will be removed in favor of getStartTimestamp / getEndTimestamp this is slated for removal in next major
151
     *
152
     * @return string
153
     */
154
    public function getTimestamp($format = 'U')
155
    {
156
        trigger_error('Deprecated in favor of splitting the start and end timestamps for a statement. '.
157
                'Please use setStartTimestamp($format) or setEndTimestamp($format) instead. '.
158
                'getTimestamp is now getStartTimestamp', E_USER_DEPRECATED);
159
160
        return $this->getStartTimestamp($format);
161
    }
162
163
    /**
164
     * @param string $format
165
     *
166
     * @return bool|string
167
     */
168
    public function getStartTimestamp($format = 'U')
169
    {
170
        return date($format, $this->startTimestamp);
171
    }
172
173
    /**
174
     * @param string $format
175
     *
176
     * @return bool|string
177
     */
178
    public function getEndTimestamp($format = 'U')
179
    {
180
        return date($format, $this->endTimestamp);
181
    }
182
183
    /**
184
     * @return string
185
     */
186
    public function getNumber()
187
    {
188
        return $this->number;
189
    }
190
191
    /**
192
     * @param Transaction $transaction
193
     */
194
    public function addTransaction(Transaction $transaction)
195
    {
196
        $this->transactions[] = $transaction;
197
    }
198
199
    /**
200
     * @return float
201
     */
202
    public function getDeltaPrice()
203
    {
204
        return $this->getStartPrice() - $this->getEndPrice();
205
    }
206
}
207