@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Created by PhpStorm. |
|
4 | - * User: uruba |
|
5 | - * Date: 2/15/2016 |
|
6 | - * Time: 2:54 PM |
|
7 | - */ |
|
3 | + * Created by PhpStorm. |
|
4 | + * User: uruba |
|
5 | + * Date: 2/15/2016 |
|
6 | + * Time: 2:54 PM |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | namespace FinanCalc\Utils { |
10 | 10 |
@@ -27,7 +27,7 @@ |
||
27 | 27 | $locale = Config::getConfigField("locale"); |
28 | 28 | } |
29 | 29 | |
30 | - $localePath = FinanCalc::getPath() . "/locale/$locale.php"; |
|
30 | + $localePath = FinanCalc::getPath()."/locale/$locale.php"; |
|
31 | 31 | |
32 | 32 | if (!file_exists($localePath)) { |
33 | 33 | return null; |
@@ -199,10 +199,10 @@ |
||
199 | 199 | private function newDateIntervalAbsolute($years, $months, $days) { |
200 | 200 | $this->setdateInterval( |
201 | 201 | new DateInterval( |
202 | - "P" . |
|
203 | - (string)$years . "Y" . |
|
204 | - (string)$months . "M" . |
|
205 | - (string)$days . "D" |
|
202 | + "P". |
|
203 | + (string)$years."Y". |
|
204 | + (string)$months."M". |
|
205 | + (string)$days."D" |
|
206 | 206 | ) |
207 | 207 | ); |
208 | 208 | } |
@@ -1,32 +1,32 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * FinanCalc |
|
4 | - * |
|
5 | - * A lightweight, simple and easy PHP library for calculating annuities (e.g., mortgages) |
|
6 | - * and other financial instruments according to various input data |
|
7 | - * |
|
8 | - * |
|
9 | - * DISCLAIMER |
|
10 | - * You are free to use/modify/extend the library as you please - for it to serve your purpose. |
|
11 | - * As per the (un)license, the software is provided as is and the original author cannot be held liable |
|
12 | - * for any losses/damages directly or indirectly resulting from using thereof. |
|
13 | - * Attribution is welcome, but certainly not required. |
|
14 | - * |
|
15 | - * NOTE |
|
16 | - * The library is currently work-in-progress and it is certain that new features will be added in the process. |
|
17 | - * Consider this, therefore, as a preview product prone to abrupt and extensive changes that may affect functionality |
|
18 | - * of an external code adapted to a prior version(s) of the library. |
|
19 | - * Always explore the provisional compatibility of the library with your project in case you upgrade to a new version |
|
20 | - * of the library (by means of an extensive testing of the code in which you are exerting the library's features). |
|
21 | - * |
|
22 | - * PREREQUISITES |
|
23 | - * PHP 5.5+ |
|
24 | - * Module php-bcmath |
|
25 | - * |
|
26 | - * @author Václav Uruba |
|
27 | - * @version 0.3 |
|
28 | - * @license http://unlicense.org The Unlicense |
|
29 | - */ |
|
3 | + * FinanCalc |
|
4 | + * |
|
5 | + * A lightweight, simple and easy PHP library for calculating annuities (e.g., mortgages) |
|
6 | + * and other financial instruments according to various input data |
|
7 | + * |
|
8 | + * |
|
9 | + * DISCLAIMER |
|
10 | + * You are free to use/modify/extend the library as you please - for it to serve your purpose. |
|
11 | + * As per the (un)license, the software is provided as is and the original author cannot be held liable |
|
12 | + * for any losses/damages directly or indirectly resulting from using thereof. |
|
13 | + * Attribution is welcome, but certainly not required. |
|
14 | + * |
|
15 | + * NOTE |
|
16 | + * The library is currently work-in-progress and it is certain that new features will be added in the process. |
|
17 | + * Consider this, therefore, as a preview product prone to abrupt and extensive changes that may affect functionality |
|
18 | + * of an external code adapted to a prior version(s) of the library. |
|
19 | + * Always explore the provisional compatibility of the library with your project in case you upgrade to a new version |
|
20 | + * of the library (by means of an extensive testing of the code in which you are exerting the library's features). |
|
21 | + * |
|
22 | + * PREREQUISITES |
|
23 | + * PHP 5.5+ |
|
24 | + * Module php-bcmath |
|
25 | + * |
|
26 | + * @author Václav Uruba |
|
27 | + * @version 0.3 |
|
28 | + * @license http://unlicense.org The Unlicense |
|
29 | + */ |
|
30 | 30 | namespace FinanCalc { |
31 | 31 | use Exception; |
32 | 32 | use FinanCalc\Constants\ErrorMessages; |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | |
125 | 125 | private function populateFactoryClassesArray() |
126 | 126 | { |
127 | - $factoryFiles = glob(FinanCalc::getPath() . Config::getConfigField('factories_relative_path') . '/*.php'); |
|
127 | + $factoryFiles = glob(FinanCalc::getPath().Config::getConfigField('factories_relative_path').'/*.php'); |
|
128 | 128 | $factoriesNamespace = Config::getConfigField('factories_namespace'); |
129 | 129 | |
130 | 130 | foreach ($factoryFiles as $factoryFile) { |
@@ -132,12 +132,12 @@ discard block |
||
132 | 132 | $fileTokens = token_get_all($factoryFileContents); |
133 | 133 | |
134 | 134 | for ($i = 2; $i < count($fileTokens); $i++) { |
135 | - if ($fileTokens[$i - 2][0] == T_CLASS) { |
|
135 | + if ($fileTokens[$i-2][0] == T_CLASS) { |
|
136 | 136 | $factoryClassName = $fileTokens[$i][1]; |
137 | 137 | try { |
138 | 138 | /** @noinspection PhpIncludeInspection */ |
139 | 139 | require_once($factoryFile); |
140 | - $factoryClassReflector = new ReflectionClass($factoriesNamespace . '\\' . $factoryClassName); |
|
140 | + $factoryClassReflector = new ReflectionClass($factoriesNamespace.'\\'.$factoryClassName); |
|
141 | 141 | } catch (ReflectionException $e) { |
142 | 142 | error_log(ErrorMessages::getFactoryClassExpectedInNamespaceMessage($factoryClassName, |
143 | 143 | $factoriesNamespace)); |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -spl_autoload_register(function ($class) { |
|
3 | +spl_autoload_register(function($class) { |
|
4 | 4 | $exploded_class = explode("\\", $class); |
5 | 5 | |
6 | 6 | if (count($exploded_class) > 1) { |
@@ -12,9 +12,9 @@ discard block |
||
12 | 12 | $relative_class_path = implode("/", $exploded_class); |
13 | 13 | |
14 | 14 | $absolute_class_path = |
15 | - dirname(dirname(__FILE__)) . |
|
16 | - '/' . |
|
17 | - $relative_class_path . |
|
15 | + dirname(dirname(__FILE__)). |
|
16 | + '/'. |
|
17 | + $relative_class_path. |
|
18 | 18 | '.php'; |
19 | 19 | |
20 | 20 | if (file_exists($absolute_class_path)) { |
@@ -29,7 +29,7 @@ |
||
29 | 29 | $domDocument->appendChild($rootElem); |
30 | 30 | |
31 | 31 | $funcArrayToXML = |
32 | - function (\DOMElement $parentNode, $inputArray) |
|
32 | + function(\DOMElement $parentNode, $inputArray) |
|
33 | 33 | use ($domDocument, &$funcArrayToXML) { |
34 | 34 | foreach ($inputArray as $key => $value) { |
35 | 35 | $key = preg_replace('/(^[0-9])/', '_\1', str_replace(' ', '_', $key)); |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | */ |
14 | 14 | public static function checkIfNotNegative() |
15 | 15 | { |
16 | - return function ($param) { |
|
16 | + return function($param) { |
|
17 | 17 | Helpers::checkIfNotNegativeNumberOrThrowAnException($param); |
18 | 18 | }; |
19 | 19 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public static function checkIfPositive() |
25 | 25 | { |
26 | - return function ($param) { |
|
26 | + return function($param) { |
|
27 | 27 | Helpers::checkIfPositiveNumberOrThrowAnException($param); |
28 | 28 | }; |
29 | 29 | } |
@@ -53,11 +53,11 @@ |
||
53 | 53 | } |
54 | 54 | } |
55 | 55 | |
56 | - $processArray = function ($inputArray) use (&$processArray) { |
|
56 | + $processArray = function($inputArray) use (&$processArray) { |
|
57 | 57 | $processedArray = array(); |
58 | 58 | foreach ($inputArray as $key => $prop) { |
59 | 59 | if (is_string($prop)) { |
60 | - $propGetter = "get" . ucfirst($prop); |
|
60 | + $propGetter = "get".ucfirst($prop); |
|
61 | 61 | if (method_exists($this, $propGetter)) { |
62 | 62 | $processedArray[is_string($key) ? $key : $prop] = call_user_func(array($this, $propGetter)); |
63 | 63 | } else { |
@@ -80,11 +80,11 @@ |
||
80 | 80 | return (string)number_format((float)$roundedNumber, $precision); |
81 | 81 | } |
82 | 82 | |
83 | - /** |
|
84 | - * @param $roundedNumber |
|
85 | - * @param $precision |
|
86 | - * @return string |
|
87 | - */ |
|
83 | + /** |
|
84 | + * @param $roundedNumber |
|
85 | + * @param $precision |
|
86 | + * @return string |
|
87 | + */ |
|
88 | 88 | public static function round_up($roundedNumber, $precision = 2) |
89 | 89 | { |
90 | 90 | return (string)ceil((float)$roundedNumber * pow(10, $precision)) / pow(10, $precision); |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | public function getDebtSingleRepayment_Rounded() { |
298 | 298 | // single repayment 'K = PV/((1-v^n)/i)' |
299 | 299 | return MathFuncs::round_up( |
300 | - MathFuncs::div( |
|
300 | + MathFuncs::div( |
|
301 | 301 | $this->debtPrincipal, |
302 | 302 | MathFuncs::div( |
303 | 303 | MathFuncs::sub( |
@@ -338,33 +338,33 @@ discard block |
||
338 | 338 | return $repayments; |
339 | 339 | } |
340 | 340 | |
341 | - /** |
|
342 | - * @return array |
|
343 | - */ |
|
341 | + /** |
|
342 | + * @return array |
|
343 | + */ |
|
344 | 344 | public function getDebtRepaymentsAsArrays_Rounded() |
345 | 345 | { |
346 | 346 | $repayments = array(); |
347 | 347 | $i = 1; |
348 | 348 | $balance = $this->debtPrincipal; |
349 | 349 | foreach ($this->debtRepayments as $repayment) { |
350 | - if($balance > $repayment->getTotalAmount()) { |
|
351 | - $totalAmount = MathFuncs::round_up($repayment->getTotalAmount(), 2); |
|
352 | - $interestAmount = MathFuncs::round($repayment->getInterestAmount(), 2); |
|
353 | - $principalAmount = MathFuncs::round($totalAmount - $interestAmount, 2); |
|
354 | - } |
|
355 | - else { |
|
356 | - $interestAmount = MathFuncs::round($repayment->getInterestAmount(), 2); |
|
357 | - $totalAmount = MathFuncs::round(MathFuncs::add($balance, $interestAmount), 2); |
|
358 | - $principalAmount = MathFuncs::round($balance, 2); |
|
359 | - } |
|
350 | + if($balance > $repayment->getTotalAmount()) { |
|
351 | + $totalAmount = MathFuncs::round_up($repayment->getTotalAmount(), 2); |
|
352 | + $interestAmount = MathFuncs::round($repayment->getInterestAmount(), 2); |
|
353 | + $principalAmount = MathFuncs::round($totalAmount - $interestAmount, 2); |
|
354 | + } |
|
355 | + else { |
|
356 | + $interestAmount = MathFuncs::round($repayment->getInterestAmount(), 2); |
|
357 | + $totalAmount = MathFuncs::round(MathFuncs::add($balance, $interestAmount), 2); |
|
358 | + $principalAmount = MathFuncs::round($balance, 2); |
|
359 | + } |
|
360 | 360 | |
361 | - $beginningBalance = $balance; |
|
362 | - $endingBalance = MathFuncs::sub($balance, $principalAmount); |
|
363 | - $balance = MathFuncs::sub($balance, $principalAmount); |
|
361 | + $beginningBalance = $balance; |
|
362 | + $endingBalance = MathFuncs::sub($balance, $principalAmount); |
|
363 | + $balance = MathFuncs::sub($balance, $principalAmount); |
|
364 | 364 | |
365 | 365 | $repayments[$i++] = [ |
366 | - "beginningBalance" => MathFuncs::round($beginningBalance, 2), |
|
367 | - "totalAmount" => $totalAmount, |
|
366 | + "beginningBalance" => MathFuncs::round($beginningBalance, 2), |
|
367 | + "totalAmount" => $totalAmount, |
|
368 | 368 | "principalAmount" => $principalAmount, |
369 | 369 | "interestAmount" => $interestAmount, |
370 | 370 | "endingBalance" => MathFuncs::round($endingBalance, 2) |
@@ -347,10 +347,10 @@ |
||
347 | 347 | $i = 1; |
348 | 348 | $balance = $this->debtPrincipal; |
349 | 349 | foreach ($this->debtRepayments as $repayment) { |
350 | - if($balance > $repayment->getTotalAmount()) { |
|
350 | + if ($balance > $repayment->getTotalAmount()) { |
|
351 | 351 | $totalAmount = MathFuncs::round_up($repayment->getTotalAmount(), 2); |
352 | 352 | $interestAmount = MathFuncs::round($repayment->getInterestAmount(), 2); |
353 | - $principalAmount = MathFuncs::round($totalAmount - $interestAmount, 2); |
|
353 | + $principalAmount = MathFuncs::round($totalAmount-$interestAmount, 2); |
|
354 | 354 | } |
355 | 355 | else { |
356 | 356 | $interestAmount = MathFuncs::round($repayment->getInterestAmount(), 2); |
@@ -351,8 +351,7 @@ |
||
351 | 351 | $totalAmount = MathFuncs::round_up($repayment->getTotalAmount(), 2); |
352 | 352 | $interestAmount = MathFuncs::round($repayment->getInterestAmount(), 2); |
353 | 353 | $principalAmount = MathFuncs::round($totalAmount - $interestAmount, 2); |
354 | - } |
|
355 | - else { |
|
354 | + } else { |
|
356 | 355 | $interestAmount = MathFuncs::round($repayment->getInterestAmount(), 2); |
357 | 356 | $totalAmount = MathFuncs::round(MathFuncs::add($balance, $interestAmount), 2); |
358 | 357 | $principalAmount = MathFuncs::round($balance, 2); |