Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
22 / 22 |
|
100.00% |
14 / 14 |
CRAP | |
100.00% |
1 / 1 |
| Depreciation | |
100.00% |
22 / 22 |
|
100.00% |
14 / 14 |
17 | |
100.00% |
1 / 1 |
| __construct | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| getStraightLineDepreciation | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getStraightLineResidualInT | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getArithmeticDegressiveDepreciationFactor | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getArithmeticDegressiveDepreciationInT | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getArithmeticDegressiveDepreciationResidualInT | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| getArithmeticProgressiveDepreciationFactor | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getArithmeticProgressiveDepreciationInT | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getArithmeticProgressiveDepreciationResidualInT | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getGeometicProgressiveDepreciationRate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getGeometicProgressiveDepreciationInT | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getGeometicProgressiveDepreciationResidualInT | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| getGeometicDegressiveDepreciationRate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getGeometicDegressiveDepreciationInT | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getGeometicDegressiveDepreciationResidualInT | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package phpOMS\Business\Finance |
| 8 | * @copyright Dennis Eichhorn |
| 9 | * @license OMS License 2.0 |
| 10 | * @version 1.0.0 |
| 11 | * @link https://jingga.app |
| 12 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace phpOMS\Business\Finance; |
| 16 | |
| 17 | /** |
| 18 | * Depreciation class. |
| 19 | * |
| 20 | * @package phpOMS\Business\Finance |
| 21 | * @license OMS License 2.0 |
| 22 | * @link https://jingga.app |
| 23 | * @since 1.0.0 |
| 24 | */ |
| 25 | final class Depreciation |
| 26 | { |
| 27 | /** |
| 28 | * Constructor |
| 29 | * |
| 30 | * @since 1.0.0 |
| 31 | * @codeCoverageIgnore |
| 32 | */ |
| 33 | private function __construct() |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Calculate linear depretiation rate |
| 39 | * |
| 40 | * @param float $start Value to depreciate |
| 41 | * @param int $duration Useful life time |
| 42 | * |
| 43 | * @return float Returns the straight line depreciation |
| 44 | * |
| 45 | * @since 1.0.0 |
| 46 | */ |
| 47 | public static function getStraightLineDepreciation(float $start, int $duration) : float |
| 48 | { |
| 49 | return $start / $duration; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Calculate the residual after a specific amount of time |
| 54 | * |
| 55 | * @param float $start Value to depreciate |
| 56 | * @param int $duration Useful life time |
| 57 | * @param int $t Time passed |
| 58 | * |
| 59 | * @return float |
| 60 | * |
| 61 | * @since 1.0.0 |
| 62 | */ |
| 63 | public static function getStraightLineResidualInT(float $start, int $duration, int $t) : float |
| 64 | { |
| 65 | return $start - self::getStraightLineDepreciation($start, $duration) * $t; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Calculate the degression factor |
| 70 | * |
| 71 | * This factor is the amount of years |
| 72 | * |
| 73 | * @param float $start Value to depreciate (reduced by residual value if required) |
| 74 | * @param float $residual Residual value |
| 75 | * @param int $duration Useful life time |
| 76 | * |
| 77 | * @return float |
| 78 | * |
| 79 | * @since 1.0.0 |
| 80 | */ |
| 81 | public static function getArithmeticDegressiveDepreciationFactor(float $start, float $residual, int $duration) : float |
| 82 | { |
| 83 | return ($start - $residual) / ($duration * ($duration + 1) / 2); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Calculate the depreciation value in period t |
| 88 | * |
| 89 | * @param float $start Value to depreciate (reduced by residual value if required) |
| 90 | * @param float $residual Residual value |
| 91 | * @param int $duration Useful life time |
| 92 | * @param int $t Period |
| 93 | * |
| 94 | * @return float |
| 95 | * |
| 96 | * @since 1.0.0 |
| 97 | */ |
| 98 | public static function getArithmeticDegressiveDepreciationInT(float $start, float $residual, int $duration, int $t) : float |
| 99 | { |
| 100 | return self::getArithmeticDegressiveDepreciationFactor($start, $residual, $duration) * ($duration - $t + 1); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Calculate the residual value after some periods |
| 105 | * |
| 106 | * @param float $start Value to depreciate (reduced by residual value if required) |
| 107 | * @param float $residual Residual value |
| 108 | * @param int $duration Useful life time |
| 109 | * @param int $t Passed periods |
| 110 | * |
| 111 | * @return float |
| 112 | * |
| 113 | * @since 1.0.0 |
| 114 | */ |
| 115 | public static function getArithmeticDegressiveDepreciationResidualInT(float $start, float $residual, int $duration, int $t) : float |
| 116 | { |
| 117 | $end = $start; |
| 118 | |
| 119 | for ($i = 1; $i <= $t; ++$i) { |
| 120 | $end -= self::getArithmeticDegressiveDepreciationInT($start, $residual, $duration, $i); |
| 121 | } |
| 122 | |
| 123 | return $end; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Calculate the progressivee factor |
| 128 | * |
| 129 | * @param float $start Value to depreciate (reduced by residual value if required) |
| 130 | * @param float $residual Residual value |
| 131 | * @param int $duration Useful life time |
| 132 | * |
| 133 | * @return float |
| 134 | * |
| 135 | * @since 1.0.0 |
| 136 | */ |
| 137 | public static function getArithmeticProgressiveDepreciationFactor(float $start, float $residual, int $duration) : float |
| 138 | { |
| 139 | return ($start - $residual) / ($duration * ($duration + 1) / 2); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Calculate the depreciation value in period t |
| 144 | * |
| 145 | * @param float $start Value to depreciate (reduced by residual value if required) |
| 146 | * @param float $residual Residual value |
| 147 | * @param int $duration Useful life time |
| 148 | * @param int $t Period |
| 149 | * |
| 150 | * @return float |
| 151 | * |
| 152 | * @since 1.0.0 |
| 153 | */ |
| 154 | public static function getArithmeticProgressiveDepreciationInT(float $start, float $residual, int $duration, int $t) : float |
| 155 | { |
| 156 | return self::getArithmeticProgressiveDepreciationFactor($start, $residual, $duration) * $t; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Calculate the residual value after some periods |
| 161 | * |
| 162 | * @param float $start Value to depreciate (reduced by residual value if required) |
| 163 | * @param float $residual Residual value |
| 164 | * @param int $duration Useful life time |
| 165 | * @param int $t Passed periods |
| 166 | * |
| 167 | * @return float |
| 168 | * |
| 169 | * @since 1.0.0 |
| 170 | */ |
| 171 | public static function getArithmeticProgressiveDepreciationResidualInT(float $start, float $residual, int $duration, int $t) : float |
| 172 | { |
| 173 | return $start - self::getArithmeticProgressiveDepreciationFactor($start, $residual, $duration) * $t * ($t + 1) / 2; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Calculate the depreciation rate |
| 178 | * |
| 179 | * @param float $start Value to depreciate (reduced by residual value if required) |
| 180 | * @param float $residual Residual value |
| 181 | * @param int $duration Useful life time |
| 182 | * |
| 183 | * @return float |
| 184 | * |
| 185 | * @since 1.0.0 |
| 186 | */ |
| 187 | public static function getGeometicProgressiveDepreciationRate(float $start, float $residual, int $duration) : float |
| 188 | { |
| 189 | return (1 - \pow($residual / $start, 1 / $duration)); |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Calculate the depreciation value in a period |
| 194 | * |
| 195 | * @param float $start Value to depreciate (reduced by residual value if required) |
| 196 | * @param float $residual Residual value |
| 197 | * @param int $duration Useful life time |
| 198 | * @param int $t Period |
| 199 | * |
| 200 | * @return float |
| 201 | * |
| 202 | * @since 1.0.0 |
| 203 | */ |
| 204 | public static function getGeometicProgressiveDepreciationInT(float $start, float $residual, int $duration, int $t) : float |
| 205 | { |
| 206 | $rate = self::getGeometicProgressiveDepreciationRate($start, $residual, $duration); |
| 207 | |
| 208 | return $start * (1 - $rate) ** ($duration - $t) * $rate; |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Calculate the residual value after some periods |
| 213 | * |
| 214 | * @param float $start Value to depreciate (reduced by residual value if required) |
| 215 | * @param float $residual Residual value |
| 216 | * @param int $duration Useful life time |
| 217 | * @param int $t Period |
| 218 | * |
| 219 | * @return float |
| 220 | * |
| 221 | * @since 1.0.0 |
| 222 | */ |
| 223 | public static function getGeometicProgressiveDepreciationResidualInT(float $start, float $residual, int $duration, int $t) : float |
| 224 | { |
| 225 | $end = $start; |
| 226 | |
| 227 | for ($i = 1; $i <= $t; ++$i) { |
| 228 | $end -= self::getGeometicProgressiveDepreciationInT($start, $residual, $duration, $i); |
| 229 | } |
| 230 | |
| 231 | return $end; |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * Calculate the depreciation rate |
| 236 | * |
| 237 | * @param float $start Value to depreciate (reduced by residual value if required) |
| 238 | * @param float $residual Residual value |
| 239 | * @param int $duration Useful life time |
| 240 | * |
| 241 | * @return float |
| 242 | * |
| 243 | * @since 1.0.0 |
| 244 | */ |
| 245 | public static function getGeometicDegressiveDepreciationRate(float $start, float $residual, int $duration) : float |
| 246 | { |
| 247 | return (1 - \pow($residual / $start, 1 / $duration)); |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * Calculate the depreciation value in a period |
| 252 | * |
| 253 | * @param float $start Value to depreciate (reduced by residual value if required) |
| 254 | * @param float $residual Residual value |
| 255 | * @param int $duration Useful life time |
| 256 | * @param int $t Period |
| 257 | * |
| 258 | * @return float |
| 259 | * |
| 260 | * @since 1.0.0 |
| 261 | */ |
| 262 | public static function getGeometicDegressiveDepreciationInT(float $start, float $residual, int $duration, int $t) : float |
| 263 | { |
| 264 | $rate = self::getGeometicDegressiveDepreciationRate($start, $residual, $duration); |
| 265 | return $start * (1 - $rate) ** ($t - 1) * $rate; |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * Calculate the residual value after some periods |
| 270 | * |
| 271 | * @param float $start Value to depreciate (reduced by residual value if required) |
| 272 | * @param float $residual Residual value |
| 273 | * @param int $duration Useful life time |
| 274 | * @param int $t Period |
| 275 | * |
| 276 | * @return float |
| 277 | * |
| 278 | * @since 1.0.0 |
| 279 | */ |
| 280 | public static function getGeometicDegressiveDepreciationResidualInT(float $start, float $residual, int $duration, int $t) : float |
| 281 | { |
| 282 | return $start * (1 - self::getGeometicDegressiveDepreciationRate($start, $residual, $duration)) ** $t; |
| 283 | } |
| 284 | } |