Conditions | 1 |
Paths | 1 |
Total Lines | 62 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
83 | public function getBondFairValue() |
||
84 | { |
||
85 | // we need to get the coupon rate per payment period = c/payment frequency |
||
86 | $couponRateForPeriod = MathFuncs::div( |
||
87 | $this->bondAnnualCouponRate, |
||
88 | $this->bondPaymentFrequency |
||
89 | ); |
||
90 | |||
91 | // similarly, we need to calculate the VIR per payment period = i/payment frequency |
||
92 | $VIRForPeriod = MathFuncs::div( |
||
93 | $this->bondVIR, |
||
94 | $this->bondPaymentFrequency |
||
95 | ); |
||
96 | |||
97 | // we also save the bond's number of payments to an auxiliary variable |
||
98 | $bondNoOfPayments = $this->getBondNoOfPayments(); |
||
99 | |||
100 | // next, we also need the present value of the unit annuity pertaining to the bond, in arrears |
||
101 | $PVofUnitBondAnnuity = |
||
102 | MathFuncs::div( |
||
103 | MathFuncs::sub( |
||
104 | 1, |
||
105 | Mathfuncs::pow( |
||
106 | MathFuncs::div( |
||
107 | 1, |
||
108 | MathFuncs::add( |
||
109 | 1, |
||
110 | $VIRForPeriod |
||
111 | ) |
||
112 | ), |
||
113 | $bondNoOfPayments |
||
114 | ) |
||
115 | ), |
||
116 | $VIRForPeriod |
||
117 | ); |
||
118 | |||
119 | // now we can use the formula to calculate the real value of the bond (i.e., the present value of its payments) |
||
120 | // PV = F*[c*PVofUnitBondAnnuity+1/((1+i)^n)] |
||
|
|||
121 | |||
122 | $fairValue = |
||
123 | MathFuncs::mul( |
||
124 | $this->bondFaceValue, |
||
125 | MathFuncs::add( |
||
126 | MathFuncs::mul( |
||
127 | $couponRateForPeriod, |
||
128 | $PVofUnitBondAnnuity |
||
129 | ), |
||
130 | MathFuncs::div( |
||
131 | 1, |
||
132 | MathFuncs::pow( |
||
133 | MathFuncs::add( |
||
134 | 1, |
||
135 | $VIRForPeriod |
||
136 | ), |
||
137 | $bondNoOfPayments |
||
138 | ) |
||
139 | ) |
||
140 | ) |
||
141 | ); |
||
142 | |||
143 | return $fairValue; |
||
144 | } |
||
145 | } |
||
147 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.