Skip to content

Commit

Permalink
- removed the unneeded DebtPaymentType meta value from DebtAmortizator
Browse files Browse the repository at this point in the history
  • Loading branch information
uruba committed Aug 18, 2015
1 parent 684545e commit 806d465
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 257 deletions.
14 changes: 4 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,10 @@ namespace `FinanCalc\Calculators`

#### DebtAmortizatorFactory (*DebtAmortizator's factory object*)
namespace `FinanCalc\Calculators\Factories`
* **newYearlyDebtAmortizationInArrears($debtPrincipal, $debtNoOfPeriods, $debtInterest)**
* **newMonthlyDebtAmortizationInArrears($debtPrincipal, $debtNoOfPeriods, $debtInterest)**
* **newDailyDebtAmortizationInArrears($debtPrincipal, $debtNoOfPeriods, $debtInterest)**
* **newDebtAmortizationInArrearsCustomPeriodLength($debtPrincipal, $debtNoOfPeriods, $debtInterest, $debtSinglePeriodLength)**
* **newYearlyDebtAmortizationInAdvance($debtPrincipal, $debtNoOfPeriods, $debtInterest)**
* **newMonthlyDebtAmortizationInAdvance($debtPrincipal, $debtNoOfPeriods, $debtInterest)**
* **newDailyDebtAmortizationInAdvance($debtPrincipal, $debtNoOfPeriods, $debtInterest)**
* **newDebtAmortizationInAdvanceCustomPeriodLength($debtPrincipal, $debtNoOfPeriods, $debtInterest, $debtSinglePeriodLength)**
* **newYearlyDebtAmortization($debtPrincipal, $debtNoOfPeriods, $debtInterest)**
* **newMonthlyDebtAmortization($debtPrincipal, $debtNoOfPeriods, $debtInterest)**
* **newDailyDebtAmortization($debtPrincipal, $debtNoOfPeriods, $debtInterest)**
* **newDebtAmortizationCustomPeriodLength($debtPrincipal, $debtNoOfPeriods, $debtInterest, $debtSinglePeriodLength)**

#### DebtInstance (*DebtAmortizator's result object*)
namespace `FinanCalc\Calculators\DebtAmortizator`
Expand All @@ -235,7 +231,6 @@ namespace `FinanCalc\Calculators\DebtAmortizator`
* **setDebtNoOfCompoundingPeriods($debtNoOfCompoundingPeriods)** – sets n
* **setDebtPeriodLength($debtPeriodLength)** – sets the length of each compounding period in days
* **setDebtInterest($debtInterest)** – sets i
* **setDebtPaymentType(AnnuityPaymentTypes $debtPaymentType)** – determines whether the compounding is done in advance or in arrears

##### Getters
* **getDebtDiscountFactor()** – gets the value of the debt's discount factor = **'v'**
Expand All @@ -250,7 +245,6 @@ namespace `FinanCalc\Calculators\DebtAmortizator`
* **getDebtDurationInDays()** – gets the duration of the debt in days
* **getDebtInterest()** – gets i
* **getDebtRepayments()** – gets the **array of RepaymentInstance** objects representing all the individual payments within the debt comprised into an array
* **getDebtPaymentType()** – gets the information whether the debt installments are repaid in advance or in arrears

#### RepaymentInstance
namespace `FinanCalc\Calculators\DebtAmortizator`
Expand Down
34 changes: 4 additions & 30 deletions src/calculators/DebtAmortizator.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

namespace FinanCalc\Calculators {
use FinanCalc\Constants\AnnuityPaymentTypes;
use FinanCalc\Calculators\DebtAmortizator\DebtInstance;
use FinanCalc\Interfaces\CalculatorInterface;

Expand All @@ -19,20 +18,17 @@ class DebtAmortizator implements CalculatorInterface {
* @param string $debtNoOfCompoundingPeriods [Number of the debt's compounding periods as a string]
* @param string $debtInterest [Value of the debt's interest in a decimal number 'multiplier' form as a string]
* @param string $debtPeriodLength [Length of each of the debt's compounding periods as a string]
* @param AnnuityPaymentTypes $debtPaymentType [Payment type of the debt]
*/
function __construct($debtPrincipal,
$debtNoOfCompoundingPeriods,
$debtPeriodLength,
$debtInterest,
AnnuityPaymentTypes $debtPaymentType) {
$debtInterest) {

// create new DebtInstance object passing on the parameters of this constructor
$this->debtInstance = new DebtInstance($debtPrincipal,
$debtNoOfCompoundingPeriods,
$debtPeriodLength,
$debtInterest,
$debtPaymentType);
$debtInterest);
}

/**
Expand All @@ -48,7 +44,6 @@ public function getResult() {


namespace FinanCalc\Calculators\DebtAmortizator {
use FinanCalc\Constants\AnnuityPaymentTypes;
use FinanCalc\Constants\Defaults;
use FinanCalc\Utils\Helpers;
use FinanCalc\Utils\MathFuncs;
Expand All @@ -68,8 +63,6 @@ class DebtInstance {
private $debtPeriodLength;
// the interest rate by which the unpaid balance is multiplied (i.e., a decimal number) = 'i'
private $debtInterest;
// payment type of the debt
private $debtPaymentType;

/**
* DebtInstance constructor
Expand All @@ -78,19 +71,16 @@ class DebtInstance {
* @param string $debtNoOfCompoundingPeriods [Number of the debt's compounding periods as a string]
* @param string $debtInterest [Value of the debt's interest in a decimal number 'multiplier' form as a string]
* @param string $debtPeriodLength [Length of each of the debt's compounding periods in days as a string]
* @param AnnuityPaymentTypes $debtPaymentType [Payment type of the debt]
* @throws \InvalidArgumentException
*/
function __construct($debtPrincipal,
$debtNoOfCompoundingPeriods,
$debtPeriodLength,
$debtInterest,
AnnuityPaymentTypes $debtPaymentType) {
$debtInterest) {
$this->setDebtPrincipalWithoutRecalculation($debtPrincipal);
$this->setDebtNoOfCompoundingPeriodsWithoutRecalculation($debtNoOfCompoundingPeriods);
$this->setDebtPeriodLength($debtPeriodLength);
$this->setDebtInterestWithoutRecalculation($debtInterest);
$this->setDebtPaymentType($debtPaymentType);
$this->calculateDebtRepayments();
}

Expand Down Expand Up @@ -154,15 +144,6 @@ public function setDebtInterest($debtInterest) {
$this->calculateDebtRepayments();
}

/**
* @param AnnuityPaymentTypes $debtPaymentType
*/
public function setDebtPaymentType(AnnuityPaymentTypes $debtPaymentType) {
if(Helpers::checkIfInstanceOfAClassOrThrowAnException($debtPaymentType, AnnuityPaymentTypes::class)) {
$this->debtPaymentType = $debtPaymentType;
}
}

/**
* Private function populating the $debtRepayments array which represents the amortization schedule
* constructed on basis of the initial parameters passed to the constructor
Expand Down Expand Up @@ -300,18 +281,11 @@ public function getDebtInterest() {
}

/**
* @return Array [Array of individual debt repayments (RepaymentInstances)]
* @return RepaymentInstance[] [Array of individual debt repayments (RepaymentInstances)]
*/
public function getDebtRepayments() {
return $this->debtRepayments;
}

/**
* @return AnnuityPaymentTypes [Gets the payment type of the debt]
*/
public function getDebtPaymentType() {
return $this->debtPaymentType;
}
}

/**
Expand Down
95 changes: 8 additions & 87 deletions src/calculators/factories/DebtAmortizatorFactory.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

namespace FinanCalc\Calculators\Factories {
use FinanCalc\Constants\AnnuityPaymentTypes;
use \FinanCalc\Constants\Defaults;
use \FinanCalc\Calculators\DebtAmortizator;
use FinanCalc\Interfaces\CalculatorFactoryAbstract;
Expand All @@ -13,94 +12,19 @@
class DebtAmortizatorFactory extends CalculatorFactoryAbstract {
const MANUFACTURED_CLASS_NAME = 'FinanCalc\\Calculators\\DebtAmortizator';

/**
* Payments IN ARREARS
*/

/**
* @param $debtPrincipal
* @param $debtNoOfPeriods
* @param $debtInterest
* @return DebtAmortizator
*/

public function newYearlyDebtAmortizationInArrears($debtPrincipal, $debtNoOfPeriods, $debtInterest)
{
return new DebtAmortizator(
$debtPrincipal,
$debtNoOfPeriods,
Defaults::LENGTH_YEAR_360_30,
$debtInterest,
new AnnuityPaymentTypes(AnnuityPaymentTypes::IN_ARREARS));
}

/**
* @param $debtPrincipal
* @param $debtNoOfPeriods
* @param $debtInterest
* @return DebtAmortizator
*/
public function newMonthlyDebtAmortizationInArrears($debtPrincipal, $debtNoOfPeriods, $debtInterest)
{
return new DebtAmortizator(
$debtPrincipal,
$debtNoOfPeriods,
Defaults::LENGTH_MONTH_360_30,
$debtInterest,
new AnnuityPaymentTypes(AnnuityPaymentTypes::IN_ARREARS));
}

/**
* @param $debtPrincipal
* @param $debtNoOfPeriods
* @param $debtInterest
* @return DebtAmortizator
*/
public function newDailyDebtAmortizationInArrears($debtPrincipal, $debtNoOfPeriods, $debtInterest)
{
return new DebtAmortizator(
$debtPrincipal,
$debtNoOfPeriods,
Defaults::LENGTH_DAY_360_30,
$debtInterest,
new AnnuityPaymentTypes(AnnuityPaymentTypes::IN_ARREARS));
}

/**
* @param $debtPrincipal
* @param $debtNoOfPeriods
* @param $debtInterest
* @param $debtSinglePeriodLength
* @return DebtAmortizator
*/
public function newDebtAmortizationInArrearsCustomPeriodLength($debtPrincipal, $debtNoOfPeriods, $debtInterest, $debtSinglePeriodLength) {
return new DebtAmortizator(
$debtPrincipal,
$debtNoOfPeriods,
$debtSinglePeriodLength,
$debtInterest,
new AnnuityPaymentTypes(AnnuityPaymentTypes::IN_ARREARS));
}

/**
* Payments IN ADVANCE
*/

/**
* @param $debtPrincipal
* @param $debtNoOfPeriods
* @param $debtInterest
* @return DebtAmortizator
*/

public function newYearlyDebtAmortizationInAdvance($debtPrincipal, $debtNoOfPeriods, $debtInterest)
public function newYearlyDebtAmortization($debtPrincipal, $debtNoOfPeriods, $debtInterest)
{
return new DebtAmortizator(
$debtPrincipal,
$debtNoOfPeriods,
Defaults::LENGTH_YEAR_360_30,
$debtInterest,
new AnnuityPaymentTypes(AnnuityPaymentTypes::IN_ADVANCE));
$debtInterest);
}

/**
Expand All @@ -109,14 +33,13 @@ public function newYearlyDebtAmortizationInAdvance($debtPrincipal, $debtNoOfPeri
* @param $debtInterest
* @return DebtAmortizator
*/
public function newMonthlyDebtAmortizationInAdvance($debtPrincipal, $debtNoOfPeriods, $debtInterest)
public function newMonthlyDebtAmortization($debtPrincipal, $debtNoOfPeriods, $debtInterest)
{
return new DebtAmortizator(
$debtPrincipal,
$debtNoOfPeriods,
Defaults::LENGTH_MONTH_360_30,
$debtInterest,
new AnnuityPaymentTypes(AnnuityPaymentTypes::IN_ADVANCE));
$debtInterest);
}

/**
Expand All @@ -125,14 +48,13 @@ public function newMonthlyDebtAmortizationInAdvance($debtPrincipal, $debtNoOfPer
* @param $debtInterest
* @return DebtAmortizator
*/
public function newDailyDebtAmortizationInAdvance($debtPrincipal, $debtNoOfPeriods, $debtInterest)
public function newDailyDebtAmortization($debtPrincipal, $debtNoOfPeriods, $debtInterest)
{
return new DebtAmortizator(
$debtPrincipal,
$debtNoOfPeriods,
Defaults::LENGTH_DAY_360_30,
$debtInterest,
new AnnuityPaymentTypes(AnnuityPaymentTypes::IN_ADVANCE));
$debtInterest);
}

/**
Expand All @@ -142,13 +64,12 @@ public function newDailyDebtAmortizationInAdvance($debtPrincipal, $debtNoOfPerio
* @param $debtSinglePeriodLength
* @return DebtAmortizator
*/
public function newDebtAmortizationInAdvanceCustomPeriodLength($debtPrincipal, $debtNoOfPeriods, $debtInterest, $debtSinglePeriodLength) {
public function newDebtAmortizationCustomPeriodLength($debtPrincipal, $debtNoOfPeriods, $debtInterest, $debtSinglePeriodLength) {
return new DebtAmortizator(
$debtPrincipal,
$debtNoOfPeriods,
$debtSinglePeriodLength,
$debtInterest,
new AnnuityPaymentTypes(AnnuityPaymentTypes::IN_ADVANCE));
$debtInterest);
}
}
}
Loading

0 comments on commit 806d465

Please sign in to comment.