Skip to content

Commit

Permalink
– the lambdas are no longer stored in the GLOBAL array, but served fr…
Browse files Browse the repository at this point in the history
…om a dedicated class instead
  • Loading branch information
uruba committed Jan 10, 2016
1 parent 717a9a3 commit e5b2102
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 33 deletions.
7 changes: 4 additions & 3 deletions src/Calculators/AnnuityCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Exception;
use FinanCalc\Constants\AnnuityPaymentTypes;
use FinanCalc\Constants\AnnuityValueTypes;
use FinanCalc\Constants\Lambdas;
use FinanCalc\Interfaces\Calculator\CalculatorAbstract;
use FinanCalc\Utils\Helpers;
use FinanCalc\Utils\MathFuncs;
Expand Down Expand Up @@ -72,14 +73,14 @@ function __construct($annuitySinglePaymentAmount,
* @param $annuitySinglePaymentAmount
*/
public function setAnnuitySinglePaymentAmount($annuitySinglePaymentAmount) {
$this->setProperty("annuitySinglePaymentAmount", $annuitySinglePaymentAmount, $GLOBALS["FINANCALC_FUNC_CHECK_IF_POSITIVE"]);
$this->setProperty("annuitySinglePaymentAmount", $annuitySinglePaymentAmount, Lambdas::checkIfPositive());
}

/**
* @param $annuityNoOfCompoundingPeriods
*/
public function setAnnuityNoOfCompoundingPeriods($annuityNoOfCompoundingPeriods) {
$this->setProperty("annuityNoOfCompoundingPeriods", $annuityNoOfCompoundingPeriods, $GLOBALS["FINANCALC_FUNC_CHECK_IF_NOT_NEGATIVE"]);
$this->setProperty("annuityNoOfCompoundingPeriods", $annuityNoOfCompoundingPeriods, Lambdas::checkIfNotNegative());

if ($this->annuityPeriodLength !== null) {
$this->setAnnuityPeriodLength($this->annuityPeriodLength);
Expand All @@ -103,7 +104,7 @@ public function setAnnuityPeriodLength(TimeSpan $annuityPeriodLength) {
* @param $annuityInterest
*/
public function setAnnuityInterest($annuityInterest) {
$this->setProperty("annuityInterest", $annuityInterest, $GLOBALS["FINANCALC_FUNC_CHECK_IF_POSITIVE"]);
$this->setProperty("annuityInterest", $annuityInterest, Lambdas::checkIfPositive());
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Calculators/BondDurationCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace FinanCalc\Calculators {

use FinanCalc\Constants\Lambdas;
use FinanCalc\Interfaces\Calculator\BondCalculatorAbstract;
use FinanCalc\Utils\MathFuncs;

Expand Down Expand Up @@ -66,7 +67,7 @@ function __construct($bondFaceValue,
* @param $bondAnnualYield
*/
public function setBondAnnualYield($bondAnnualYield) {
$this->setProperty("bondAnnualYield", $bondAnnualYield, $GLOBALS["FINANCALC_FUNC_CHECK_IF_POSITIVE"]);
$this->setProperty("bondAnnualYield", $bondAnnualYield, Lambdas::checkIfPositive());
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Calculators/BondFairValueCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace FinanCalc\Calculators {

use FinanCalc\Constants\Lambdas;
use FinanCalc\Interfaces\Calculator\BondCalculatorAbstract;
use FinanCalc\Utils\MathFuncs;

Expand Down Expand Up @@ -61,7 +62,7 @@ function __construct($bondFaceValue,
* @param $bondVIR
*/
public function setBondVIR($bondVIR) {
$this->setProperty("bondVIR", $bondVIR, $GLOBALS["FINANCALC_FUNC_CHECK_IF_POSITIVE"]);
$this->setProperty("bondVIR", $bondVIR, Lambdas::checkIfPositive());
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Calculators/BondYTMCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace FinanCalc\Calculators {

use FinanCalc\Constants\Lambdas;
use FinanCalc\Interfaces\Calculator\BondCalculatorAbstract;
use FinanCalc\Utils\MathFuncs;

Expand Down Expand Up @@ -61,7 +62,7 @@ function __construct($bondFaceValue,
* @param $bondMarketValue
*/
public function setBondMarketValue($bondMarketValue) {
$this->setProperty("bondMarketValue", $bondMarketValue, $GLOBALS["FINANCALC_FUNC_CHECK_IF_POSITIVE"]);
$this->setProperty("bondMarketValue", $bondMarketValue, Lambdas::checkIfPositive());
}

/**
Expand Down
9 changes: 5 additions & 4 deletions src/Calculators/DebtAmortizator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace FinanCalc\Calculators {

use DateTime;
use FinanCalc\Constants\Lambdas;
use FinanCalc\Interfaces\Calculator\CalculatorAbstract;
use FinanCalc\Utils\MathFuncs;
use FinanCalc\Utils\Time\TimeSpan;
Expand Down Expand Up @@ -70,21 +71,21 @@ function __construct($debtPrincipal,
* @param $debtPrincipal
*/
private function setDebtPrincipalWithoutRecalculation($debtPrincipal) {
$this->setProperty("debtPrincipal", $debtPrincipal, $GLOBALS["FINANCALC_FUNC_CHECK_IF_POSITIVE"]);
$this->setProperty("debtPrincipal", $debtPrincipal, Lambdas::checkIfPositive());
}

/**
* @param $debtNoOfCompoundingPeriods
*/
private function setDebtNoOfCompoundingPeriodsWithoutRecalculation($debtNoOfCompoundingPeriods) {
$this->setProperty("debtNoOfCompoundingPeriods", $debtNoOfCompoundingPeriods, $GLOBALS["FINANCALC_FUNC_CHECK_IF_POSITIVE"]);
$this->setProperty("debtNoOfCompoundingPeriods", $debtNoOfCompoundingPeriods, Lambdas::checkIfPositive());
}

/**
* @param $debtInterest
*/
private function setDebtInterestWithoutRecalculation($debtInterest) {
$this->setProperty("debtInterest", $debtInterest, $GLOBALS["FINANCALC_FUNC_CHECK_IF_POSITIVE"]);
$this->setProperty("debtInterest", $debtInterest, Lambdas::checkIfPositive());
}

/**
Expand All @@ -107,7 +108,7 @@ public function setDebtNoOfCompoundingPeriods($debtNoOfCompoundingPeriods) {
* @param $debtPeriodLength
*/
public function setDebtPeriodLength(TimeSpan $debtPeriodLength) {
$this->setProperty("debtPeriodLength", $debtPeriodLength, $GLOBALS["FINANCALC_FUNC_CHECK_IF_POSITIVE"]);
$this->setProperty("debtPeriodLength", $debtPeriodLength, Lambdas::checkIfPositive());
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/Calculators/SimpleDiscountCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace FinanCalc\Calculators {

use FinanCalc\Constants\Lambdas;
use FinanCalc\Interfaces\Calculator\CalculatorAbstract;
use FinanCalc\Utils\MathFuncs;
use FinanCalc\Utils\Time\TimeSpan;
Expand Down Expand Up @@ -36,21 +37,21 @@ function __construct($amountDue,
* @param $amountDue
*/
public function setAmountDue($amountDue) {
$this->setProperty("amountDue", $amountDue, $GLOBALS["FINANCALC_FUNC_CHECK_IF_POSITIVE"]);
$this->setProperty("amountDue", $amountDue, Lambdas::checkIfPositive());
}

/**
* @param $annualDiscountRate
*/
public function setAnnualDiscountRate($annualDiscountRate) {
$this->setProperty("annualDiscountRate", $annualDiscountRate, $GLOBALS["FINANCALC_FUNC_CHECK_IF_POSITIVE"]);
$this->setProperty("annualDiscountRate", $annualDiscountRate, Lambdas::checkIfPositive());
}

/**
* @param TimeSpan $time
*/
public function setTime(TimeSpan $time) {
$this->setProperty("time", $time, $GLOBALS["FINANCALC_FUNC_CHECK_IF_POSITIVE"]);
$this->setProperty("time", $time, Lambdas::checkIfPositive());
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/Calculators/SimpleInterestCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace FinanCalc\Calculators {

use Exception;
use FinanCalc\Constants\Lambdas;
use FinanCalc\Interfaces\Calculator\CalculatorAbstract;
use FinanCalc\Utils\MathFuncs;
use FinanCalc\Utils\Time\TimeSpan;
Expand Down Expand Up @@ -38,21 +39,21 @@ function __construct($principal,
* @param $principal
*/
public function setPrincipal($principal) {
$this->setProperty("principal", $principal, $GLOBALS["FINANCALC_FUNC_CHECK_IF_POSITIVE"]);
$this->setProperty("principal", $principal, Lambdas::checkIfPositive());
}

/**
* @param $annualInterestRate
*/
public function setAnnualInterestRate($annualInterestRate) {
$this->setProperty("annualInterestRate", $annualInterestRate, $GLOBALS["FINANCALC_FUNC_CHECK_IF_POSITIVE"]);
$this->setProperty("annualInterestRate", $annualInterestRate, Lambdas::checkIfPositive());
}

/**
* @param TimeSpan $time
*/
public function setTime(TimeSpan $time) {
$this->setProperty("time", $time, $GLOBALS["FINANCALC_FUNC_CHECK_IF_POSITIVE"]);
$this->setProperty("time", $time, Lambdas::checkIfPositive());
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Calculators/StockDividendDiscountModelCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace FinanCalc\Calculators {

use Exception;
use FinanCalc\Constants\Lambdas;
use FinanCalc\Constants\StockDDMTypes;
use FinanCalc\Interfaces\Calculator\CalculatorAbstract;
use FinanCalc\Utils\Helpers;
Expand Down Expand Up @@ -69,14 +70,14 @@ public function setDividendDiscountModelType(StockDDMTypes $dividendDiscountMode
* @param $stockVIR
*/
public function setStockVIR($stockVIR){
$this->setProperty("stockVIR", $stockVIR, $GLOBALS["FINANCALC_FUNC_CHECK_IF_POSITIVE"]);
$this->setProperty("stockVIR", $stockVIR, Lambdas::checkIfPositive());
}

/**
* @param $stockAnnualDividendsValue
*/
public function setStockAnnualDividendsValue($stockAnnualDividendsValue) {
$this->setProperty("stockAnnualDividendsValue", $stockAnnualDividendsValue, $GLOBALS["FINANCALC_FUNC_CHECK_IF_POSITIVE"]);
$this->setProperty("stockAnnualDividendsValue", $stockAnnualDividendsValue, Lambdas::checkIfPositive());
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/Calculators/StockInvestmentRatiosCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace FinanCalc\Calculators {

use FinanCalc\Constants\Lambdas;
use FinanCalc\Interfaces\Calculator\CalculatorAbstract;
use FinanCalc\Utils\MathFuncs;

Expand Down Expand Up @@ -47,21 +48,21 @@ function __construct($totalDividends,
* @param $totalDividends
*/
public function setTotalDividends($totalDividends) {
$this->setProperty("totalDividends", $totalDividends, $GLOBALS["FINANCALC_FUNC_CHECK_IF_POSITIVE"]);
$this->setProperty("totalDividends", $totalDividends, Lambdas::checkIfPositive());
}

/**
* @param $earningsAfterTaxes
*/
public function setEarningsAfterTaxes($earningsAfterTaxes) {
$this->setProperty("earningsAfterTaxes", $earningsAfterTaxes, $GLOBALS["FINANCALC_FUNC_CHECK_IF_POSITIVE"]);
$this->setProperty("earningsAfterTaxes", $earningsAfterTaxes, Lambdas::checkIfPositive());
}

/**
* @param $noOfStocks
*/
public function setNoOfStocks($noOfStocks) {
$this->setProperty("noOfStocks", $noOfStocks, $GLOBALS["FINANCALC_FUNC_CHECK_IF_POSITIVE"]);
$this->setProperty("noOfStocks", $noOfStocks, Lambdas::checkIfPositive());
}

/**
Expand Down
32 changes: 32 additions & 0 deletions src/Constants/Lambdas.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
namespace FinanCalc\Constants {

use FinanCalc\Utils\Helpers;

/**
* Class Lambdas
* @package FinanCalc\Constants
*/
class Lambdas {

/**
* @return \Closure
*/
public static function checkIfNotNegative() {
return function($param) {
Helpers::checkIfNotNegativeNumberOrThrowAnException($param);
};
}

/**
* @return \Closure
*/
public static function checkIfPositive() {
return function($param) {
Helpers::checkIfPositiveNumberOrThrowAnException($param);
};
}

}
}

1 change: 0 additions & 1 deletion src/init/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

require_once('autoloader.php');
require_once('lambdas.php');

\FinanCalc\Utils\Config::init();
11 changes: 0 additions & 11 deletions src/init/lambdas.php

This file was deleted.

0 comments on commit e5b2102

Please sign in to comment.