jiangbianwanghai /
bankloan
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Amortization Schedule Calculator |
||
| 4 | */ |
||
| 5 | namespace Jiangbianwanghai\BankLoan; |
||
| 6 | class BankLoan |
||
| 7 | { |
||
| 8 | /** |
||
| 9 | * @var int |
||
| 10 | */ |
||
| 11 | protected $loanAmount = 100000; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @var int |
||
| 15 | */ |
||
| 16 | protected $year = 1; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var float |
||
| 20 | */ |
||
| 21 | protected $interestRate = 0; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var int |
||
| 25 | */ |
||
| 26 | protected $interestRateChangeIndex = 0; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var int |
||
| 30 | */ |
||
| 31 | protected $bank = 'PBC'; // The people's bank of China |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var int |
||
| 35 | */ |
||
| 36 | private $_monthlyinterestRate = 0; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var int |
||
| 40 | */ |
||
| 41 | private $_interestPartTemp = 0; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * init param |
||
| 45 | * |
||
| 46 | * @param int $config['loanAmount'] |
||
|
0 ignored issues
–
show
|
|||
| 47 | * @param int $config['year'] |
||
|
0 ignored issues
–
show
There is no parameter named
$config['year']. Did you maybe mean $config?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit. Consider the following example. The parameter /**
* @param array $germany
* @param array $ireland
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was changed, but the annotation was not. Loading history...
|
|||
| 48 | * @param int $config['interestRate'] |
||
|
0 ignored issues
–
show
There is no parameter named
$config['interestRate']. Did you maybe mean $config?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit. Consider the following example. The parameter /**
* @param array $germany
* @param array $ireland
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was changed, but the annotation was not. Loading history...
|
|||
| 49 | * @param int $config['interestRateChangeIndex'] |
||
|
0 ignored issues
–
show
There is no parameter named
$config['interestRateChangeIndex']. Did you maybe mean $config?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit. Consider the following example. The parameter /**
* @param array $germany
* @param array $ireland
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was changed, but the annotation was not. Loading history...
|
|||
| 50 | * |
||
| 51 | */ |
||
| 52 | 9 | public function __construct($config) |
|
| 53 | { |
||
| 54 | 9 | if (isset($config['loanAmount']) && !empty($config['loanAmount'])) { |
|
| 55 | 9 | $this->loanAmount = $config['loanAmount']; |
|
| 56 | 9 | } |
|
| 57 | 9 | View Code Duplication | if (isset($config['year']) && !empty($config['year'])) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 58 | 9 | $this->year = $config['year']; |
|
| 59 | 9 | } |
|
| 60 | 9 | View Code Duplication | if (isset($config['interestRateChangeIndex']) && !empty($config['interestRateChangeIndex'])) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 61 | 3 | $this->interestRateChangeIndex = $config['interestRateChangeIndex']; |
|
| 62 | 3 | } |
|
| 63 | 9 | if (isset($config['interestRate']) && !empty($config['interestRate'])) { |
|
| 64 | 3 | $this->interestRate = $config['interestRate']/100; |
|
|
0 ignored issues
–
show
It seems like
$config['interestRate'] / 100 can also be of type integer. However, the property $interestRate is declared as type double. Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||
| 65 | 3 | } else { |
|
| 66 | 6 | $this->_getinterestRate(); |
|
| 67 | } |
||
| 68 | 9 | $this->_monthlyinterestRate = $this->interestRate/12; |
|
|
0 ignored issues
–
show
It seems like
$this->interestRate / 12 can also be of type double. However, the property $_monthlyinterestRate is declared as type integer. Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||
| 69 | 9 | $this->period = $this->year*12; |
|
|
0 ignored issues
–
show
The property
period does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
Loading history...
|
|||
| 70 | 9 | } |
|
| 71 | |||
| 72 | /** |
||
| 73 | * Equal Loan Payments |
||
| 74 | * |
||
| 75 | * @return array |
||
| 76 | * |
||
| 77 | */ |
||
| 78 | 9 | public function getELP() |
|
| 79 | { |
||
| 80 | 9 | $output = []; |
|
| 81 | 9 | $paymentAmount = $this->loanAmount*($this->_monthlyinterestRate*pow(1+$this->_monthlyinterestRate, $this->year*12))/(pow(1+$this->_monthlyinterestRate, $this->year*12)-1); // Payment Amount |
|
| 82 | 9 | $loanAmount = $this->loanAmount; |
|
| 83 | 9 | $initPrincipalPart = 0; // Init Prncipal Part |
|
| 84 | 9 | for ($i=1; $i <= $this->period; $i++) { |
|
| 85 | 9 | $loanAmount = $loanAmount - $initPrincipalPart; |
|
| 86 | 9 | $interestPart = $loanAmount*$this->_monthlyinterestRate; |
|
| 87 | 9 | $output['period'][$i]['ip'] = sprintf("%.2f", $interestPart); // Interest Part |
|
| 88 | 9 | $output['period'][$i]['pa'] = sprintf("%.2f", $paymentAmount); // Payment Amount |
|
| 89 | 9 | $principal = $initPrincipalPart = $paymentAmount - $interestPart; |
|
| 90 | 9 | $output['period'][$i]['pp'] = sprintf("%.2f", $principal); // Principal Part |
|
| 91 | 9 | $output['period'][$i]['bo'] = sprintf("%.2f", abs($loanAmount-$principal)); // Banlance Owed |
|
| 92 | 9 | } |
|
| 93 | 9 | return $output; |
|
| 94 | } |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Equal Principal Payments |
||
| 98 | * |
||
| 99 | * @return array |
||
| 100 | * |
||
| 101 | */ |
||
| 102 | 9 | public function getEPP() |
|
| 103 | { |
||
| 104 | 9 | $output = []; |
|
| 105 | 9 | $principalPart = $this->loanAmount/($this->year*12); // Principal Part |
|
| 106 | 9 | $loanAmountInterest = 0; |
|
| 107 | 9 | $loanAmount = $this->loanAmount; |
|
| 108 | 9 | $equalAll = $equalItem = 0; |
|
| 109 | 9 | for ($i=1; $i <= $this->period; $i++) { |
|
| 110 | 9 | if ($i > 1) |
|
| 111 | 9 | $loanAmount = $loanAmount - $principalPart; |
|
| 112 | 9 | $interestPart = $loanAmount*$this->_monthlyinterestRate; |
|
| 113 | 9 | $loanAmountInterest += $interestPart; |
|
| 114 | 9 | $output['period'][$i]['ip'] = sprintf("%.2f", $interestPart); // Interest Part |
|
| 115 | 9 | $output['period'][$i]['pp'] = sprintf("%.2f", $principalPart); // Principal Part |
|
| 116 | 9 | $output['period'][$i]['pa'] = sprintf("%.2f", $principalPart+$interestPart); // Payment Amount |
|
| 117 | 9 | $output['period'][$i]['bo'] = sprintf("%.2f", $loanAmount - $principalPart); // Balance Owed |
|
| 118 | 9 | $i > 1 && $equalItem = $this->_interestPartTemp - $interestPart; |
|
| 119 | 9 | $this->_interestPartTemp = $interestPart; |
|
| 120 | 9 | $equalAll += $equalItem; |
|
| 121 | 9 | } |
|
| 122 | 9 | $output['ti'] = sprintf("%.2f", $loanAmountInterest); // loanAmount Interest |
|
| 123 | 9 | $output['tp'] = sprintf("%.2f", $this->loanAmount+$loanAmountInterest); // loanAmount Payments |
|
| 124 | 9 | $output['equal'] = sprintf("%.2f", $equalAll/($this->year*12 - 1)); |
|
| 125 | 9 | return $output; |
|
| 126 | } |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Get ank interestRate |
||
| 130 | */ |
||
| 131 | 6 | private function _getinterestRate() |
|
| 132 | { |
||
| 133 | 6 | $config = require(__DIR__.'/config.php'); |
|
| 134 | 6 | if ($this->interestRateChangeIndex) { |
|
| 135 | 3 | if (isset($config[$this->bank][$this->interestRateChangeIndex])) { |
|
| 136 | 3 | $currConfig = $config[$this->bank][$this->interestRateChangeIndex]; |
|
| 137 | 3 | } |
|
| 138 | 3 | } else { |
|
| 139 | 3 | $currConfig = end($config[$this->bank]); |
|
| 140 | } |
||
| 141 | |||
| 142 | 6 | if (empty($this->interestRate)) { |
|
| 143 | 6 | if ($this->year <= 0.6) { |
|
| 144 | $interestRate = $currConfig[0]; |
||
|
0 ignored issues
–
show
The variable
$currConfig does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
Loading history...
|
|||
| 145 | 6 | } elseif ($this->year <= 1) { |
|
| 146 | $interestRate = $currConfig[1]; |
||
| 147 | 6 | } elseif ($this->year <= 3) { |
|
| 148 | $interestRate = $currConfig[2]; |
||
| 149 | 6 | } elseif ($this->year <= 5) { |
|
| 150 | 3 | $interestRate = $currConfig[3]; |
|
| 151 | 3 | } else { |
|
| 152 | 3 | $interestRate = $currConfig[4]; |
|
| 153 | } |
||
| 154 | 6 | $this->interestRate = $interestRate/100; |
|
|
0 ignored issues
–
show
It seems like
$interestRate / 100 can also be of type integer. However, the property $interestRate is declared as type double. Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||
| 155 | 6 | } |
|
| 156 | 6 | } |
|
| 157 | } |
||
| 158 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.