1 | <?php |
||
20 | class AnnuityCalculator extends CalculatorAbstract |
||
21 | { |
||
22 | |||
23 | // amount of each individual payment = 'K' |
||
24 | protected $annuitySinglePaymentAmount; |
||
25 | // number of periods pertaining to the interest compounding = 'n' |
||
26 | // if 'n = 0', the annuity is considered a perpetuity |
||
27 | protected $annuityNoOfCompoundingPeriods; |
||
28 | // length of a single period as a FinanCalc\Utils\Time\TimeSpan object |
||
29 | /** @var TimeSpan */ |
||
30 | protected $annuityPeriodLength; |
||
31 | // the interest rate by which the unpaid balance is multiplied (i.e., a decimal number) = 'i' |
||
32 | protected $annuityInterest; |
||
33 | |||
34 | // props returned by the getResultAsArray method by default |
||
35 | protected $propResultArray = [ |
||
36 | "annuitySinglePaymentAmount", |
||
37 | "annuityNoOfCompoundingPeriods", |
||
38 | "annuityInterest", |
||
39 | "annuityPeriodLength" => |
||
40 | [ |
||
41 | "years" => "annuityPeriodLengthInYears", |
||
42 | "months" => "annuityPeriodLengthInMonths", |
||
43 | "days" => "annuityPeriodLengthInDays" |
||
44 | ], |
||
45 | "annuityPresentValue" => |
||
46 | [ |
||
47 | "in_advance" => "annuityPresentValueInAdvance", |
||
48 | "in_arrears" => "annuityPresentValueInArrears" |
||
49 | ], |
||
50 | "annuityFutureValue" => |
||
51 | [ |
||
52 | "in_advance" => "annuityFutureValueInAdvance", |
||
53 | "in_arrears" => "annuityFutureValueInArrears" |
||
54 | ], |
||
55 | ]; |
||
56 | |||
57 | /** |
||
58 | * @param $annuitySinglePaymentAmount |
||
59 | * @param $annuityNoOfCompoundingPeriods |
||
60 | * @param $annuityPeriodLength |
||
61 | * @param $annuityInterest |
||
62 | */ |
||
63 | public function __construct( |
||
74 | |||
75 | /** |
||
76 | * @param $annuitySinglePaymentAmount |
||
77 | */ |
||
78 | public function setAnnuitySinglePaymentAmount($annuitySinglePaymentAmount) |
||
82 | |||
83 | /** |
||
84 | * @param $annuityNoOfCompoundingPeriods |
||
85 | */ |
||
86 | public function setAnnuityNoOfCompoundingPeriods($annuityNoOfCompoundingPeriods) |
||
95 | |||
96 | /** |
||
97 | * @param $annuityPeriodLength |
||
98 | */ |
||
99 | public function setAnnuityPeriodLength(TimeSpan $annuityPeriodLength) |
||
109 | |||
110 | /** |
||
111 | * @param $annuityInterest |
||
112 | */ |
||
113 | public function setAnnuityInterest($annuityInterest) |
||
117 | |||
118 | /** |
||
119 | * @return mixed |
||
120 | */ |
||
121 | public function getAnnuitySinglePaymentAmount() |
||
125 | |||
126 | /** |
||
127 | * @return mixed |
||
128 | */ |
||
129 | public function getAnnuityNoOfCompoundingPeriods() |
||
133 | |||
134 | /** |
||
135 | * @return TimeSpan |
||
136 | */ |
||
137 | public function getAnnuityPeriodLength() |
||
141 | |||
142 | /** |
||
143 | * @return string |
||
144 | */ |
||
145 | public function getAnnuityPeriodLengthInYears() |
||
149 | |||
150 | /** |
||
151 | * @return string |
||
152 | */ |
||
153 | public function getAnnuityPeriodLengthInMonths() |
||
157 | |||
158 | /** |
||
159 | * @return string |
||
160 | */ |
||
161 | public function getAnnuityPeriodLengthInDays() |
||
165 | |||
166 | /** |
||
167 | * @return mixed |
||
168 | */ |
||
169 | public function getAnnuityInterest() |
||
173 | |||
174 | /** |
||
175 | * @return string |
||
176 | * @throws Exception |
||
177 | */ |
||
178 | public function getAnnuityLengthInYears() |
||
185 | |||
186 | /** |
||
187 | * @return string |
||
188 | * @throws Exception |
||
189 | */ |
||
190 | public function getAnnuityLengthInMonths() |
||
197 | |||
198 | /** |
||
199 | * @return string |
||
200 | */ |
||
201 | public function getAnnuityLengthInDays() |
||
208 | |||
209 | /** |
||
210 | * @param DateTime $startDate |
||
211 | * @return DateTime |
||
212 | */ |
||
213 | public function getAnnuityEndDate(DateTime $startDate) |
||
219 | |||
220 | /** |
||
221 | * @param AnnuityPaymentTypes $annuityType |
||
222 | * @return null|string |
||
223 | */ |
||
224 | public function getAnnuityPresentValue(AnnuityPaymentTypes $annuityType = null) |
||
232 | |||
233 | /** |
||
234 | * @return null|string |
||
235 | */ |
||
236 | public function getAnnuityPresentValueInAdvance() |
||
243 | |||
244 | /** |
||
245 | * @return null|string |
||
246 | */ |
||
247 | public function getAnnuityPresentValueInArrears() |
||
254 | |||
255 | /** |
||
256 | * @param AnnuityPaymentTypes $annuityType |
||
257 | * @return null|string |
||
258 | */ |
||
259 | public function getAnnuityFutureValue(AnnuityPaymentTypes $annuityType = null) |
||
267 | |||
268 | /** |
||
269 | * @return null|string |
||
270 | */ |
||
271 | public function getAnnuityFutureValueInAdvance() |
||
278 | |||
279 | /** |
||
280 | * @return null|string |
||
281 | */ |
||
282 | public function getAnnuityFutureValueInArrears() |
||
288 | |||
289 | /** |
||
290 | * @param AnnuityPaymentTypes $annuityPaymentType |
||
291 | * @param AnnuityValueTypes $annuityValueType |
||
292 | * @return null|string |
||
293 | * @throws Exception |
||
294 | */ |
||
295 | public function getAnnuityValue( |
||
373 | } |
||
374 | } |
||
375 |
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: