1 | <?php |
||
16 | class DebtAmortizator extends CalculatorAbstract |
||
17 | { |
||
18 | /** @var RepaymentInstance[] */ |
||
19 | // list of individual debt's repayments as an array of RepaymentInstance objects |
||
20 | protected $debtRepayments; |
||
21 | |||
22 | // principal of the debt = 'PV' |
||
23 | protected $debtPrincipal; |
||
24 | // number of periods pertaining to the interest compounding = 'n' |
||
25 | protected $debtNoOfCompoundingPeriods; |
||
26 | // length of a single period in days |
||
27 | /** @var TimeSpan */ |
||
28 | protected $debtPeriodLength; |
||
29 | // the interest rate by which the unpaid balance is multiplied (i.e., a decimal number) = 'i' |
||
30 | protected $debtInterest; |
||
31 | |||
32 | // props returned by the getResultAsArray method by default |
||
33 | protected $propResultArray = [ |
||
34 | "debtPrincipal", |
||
35 | "debtNoOfCompoundingPeriods", |
||
36 | "debtPeriodLength" => |
||
37 | [ |
||
38 | "years" => "debtPeriodLengthInYears", |
||
39 | "months" => "debtPeriodLengthInMonths", |
||
40 | "days" => "debtPeriodLengthInDays" |
||
41 | ], |
||
42 | "debtInterest", |
||
43 | "debtDiscountFactor", |
||
44 | "debtLength" => |
||
45 | [ |
||
46 | "years" => "debtLengthInYears", |
||
47 | "months" => "debtLengthInMonths", |
||
48 | "days" => "debtLengthInDays" |
||
49 | ], |
||
50 | "debtSingleRepayment", |
||
51 | "debtRepayments" => "debtRepaymentsAsArrays" |
||
52 | ]; |
||
53 | |||
54 | /** |
||
55 | * @param $debtPrincipal |
||
56 | * @param $debtNoOfCompoundingPeriods |
||
57 | * @param TimeSpan $debtPeriodLength |
||
58 | * @param $debtInterest |
||
59 | */ |
||
60 | public function __construct( |
||
72 | |||
73 | /** |
||
74 | * @param $debtPrincipal |
||
75 | */ |
||
76 | private function setDebtPrincipalWithoutRecalculation($debtPrincipal) |
||
80 | |||
81 | /** |
||
82 | * @param $debtNoOfCompoundingPeriods |
||
83 | */ |
||
84 | private function setDebtNoOfCompoundingPeriodsWithoutRecalculation($debtNoOfCompoundingPeriods) |
||
88 | |||
89 | /** |
||
90 | * @param $debtInterest |
||
91 | */ |
||
92 | private function setDebtInterestWithoutRecalculation($debtInterest) |
||
96 | |||
97 | /** |
||
98 | * @param $debtPrincipal |
||
99 | */ |
||
100 | public function setDebtPrincipal($debtPrincipal) |
||
105 | |||
106 | /** |
||
107 | * @param $debtNoOfCompoundingPeriods |
||
108 | */ |
||
109 | public function setDebtNoOfCompoundingPeriods($debtNoOfCompoundingPeriods) |
||
114 | |||
115 | /** |
||
116 | * @param $debtPeriodLength |
||
117 | */ |
||
118 | public function setDebtPeriodLength(TimeSpan $debtPeriodLength) |
||
122 | |||
123 | /** |
||
124 | * @param $debtInterest |
||
125 | */ |
||
126 | public function setDebtInterest($debtInterest) |
||
131 | |||
132 | /** |
||
133 | * Private function populating the $debtRepayments array which represents the amortization schedule |
||
134 | * constructed on basis of the initial parameters passed to the constructor |
||
135 | */ |
||
136 | private function calculateDebtRepayments() |
||
154 | |||
155 | /** |
||
156 | * @return string [Value of the debt principal as a string] |
||
157 | */ |
||
158 | public function getDebtPrincipal() |
||
162 | |||
163 | /** |
||
164 | * @return string [Number of the debt's compounding periods as a string] |
||
165 | */ |
||
166 | public function getDebtNoOfCompoundingPeriods() |
||
170 | |||
171 | /** |
||
172 | * @return TimeSpan |
||
173 | */ |
||
174 | public function getDebtPeriodLength() |
||
178 | |||
179 | /** |
||
180 | * @return string [Length of each of the debt's compounding periods in years as a string] |
||
181 | */ |
||
182 | public function getDebtPeriodLengthInYears() |
||
186 | |||
187 | /** |
||
188 | * @return string [Length of each of the debt's compounding periods in months as a string] |
||
189 | */ |
||
190 | public function getDebtPeriodLengthInMonths() |
||
194 | |||
195 | /** |
||
196 | * @return string [Length of each of the debt's compounding periods in days as a string] |
||
197 | */ |
||
198 | public function getDebtPeriodLengthInDays() |
||
202 | |||
203 | /** |
||
204 | * @return string [Value of the debt's interest in a decimal number 'multiplier' form as a string] |
||
205 | */ |
||
206 | public function getDebtInterest() |
||
210 | |||
211 | /** |
||
212 | * @return string [Value of the debt's discount factor as a string] |
||
213 | */ |
||
214 | public function getDebtDiscountFactor() |
||
226 | |||
227 | /** |
||
228 | * @return string [Length of the debt in years as a string] |
||
229 | */ |
||
230 | public function getDebtLengthInYears() |
||
237 | |||
238 | /** |
||
239 | * @return string [Length of the debt in months as a string] |
||
240 | */ |
||
241 | public function getDebtLengthInMonths() |
||
248 | |||
249 | /** |
||
250 | * @return string [Length of the debt in years as a string] |
||
251 | */ |
||
252 | public function getDebtLengthInDays() |
||
259 | |||
260 | /** |
||
261 | * @param DateTime $startDate [The start date of the debt] |
||
262 | * @return DateTime [The end date of the debt] |
||
263 | */ |
||
264 | public function getDebtEndDate(DateTime $startDate) |
||
270 | |||
271 | /** |
||
272 | * @return string [Value of a single debt repayment instance as a string] |
||
273 | */ |
||
274 | public function getDebtSingleRepayment() |
||
291 | |||
292 | /** |
||
293 | * @return RepaymentInstance[] [Array of individual debt repayments (RepaymentInstances)] |
||
294 | */ |
||
295 | public function getDebtRepayments() |
||
299 | |||
300 | /** |
||
301 | * @return array |
||
302 | */ |
||
303 | public function getDebtRepaymentsAsArrays() |
||
317 | |||
318 | } |
||
319 | |||
366 |
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.