FutureValueOfAnnuityCalculator   A
last analyzed

Complexity

Total Complexity 22

Size/Duplication

Total Lines 182
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 22
c 4
b 0
f 0
lcom 1
cbo 1
dl 0
loc 182
rs 10

18 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 2
A getProfit() 0 9 2
A getProfitsByYear() 0 9 2
A getTotalProfit() 0 4 1
A getNetIncome() 0 4 1
A getEffectiveEvaluation() 0 8 2
A getTotalAmount() 0 4 1
A getPurchaseAmount() 0 4 1
A getProfitVat() 0 4 1
A getCharge() 0 4 1
A getAmount() 0 4 1
A setAmount() 0 6 1
A getLength() 0 4 1
A setLength() 0 6 1
A getRates() 0 4 1
A setRates() 0 6 1
A getRate() 0 4 1
A setRate() 0 6 1
1
<?php
2
3
/**
4
 * This file is part of the Investform module for webcms2.
5
 * Copyright (c) @see LICENSE
6
 */
7
8
namespace WebCMS\InvestformModule\Common;
9
10
/**
11
 * 
12
 */
13
class FutureValueOfAnnuityCalculator
14
{
15
	private $amount;
16
17
	private $length;
18
19
	private $rates;
20
21
	private $rate;
22
23
	public function __construct($amount, $length)
24
	{
25
		$this->amount = $amount;
26
		$this->length = $length;
27
28
		$this->rates = array(
29
			3 => new Rate(3, 0.07, 1.02),
30
			5 => new Rate(5, 0.07, 1.03)
31
		);
32
33
        if ($this->length > 3) {
34
            $this->rate = $this->rates[5];
35
        } else {
36
            $this->rate = $this->rates[3];
37
        }
38
	}
39
40
	public function getProfit($length = null)
41
	{
42
        if (!$length) {
43
            $length = $this->length;
44
        }
45
46
		$rate = 1 + $this->rate->getRate();
47
		return $this->amount * pow($rate, $length) - $this->amount;
48
	}
49
50
    public function getProfitsByYear()
51
    {
52
        $profits = array();
53
        for ($i=1; $i < $this->length; $i++) { 
54
            $profits[$i] = $this->getProfit($i) - $this->getProfit($i) * 0.15;
55
        }
56
57
        return $profits;
58
    }
59
60
	public function getTotalProfit()
61
	{
62
		return $this->amount + $this->getNetIncome();
63
	}
64
65
	public function getNetIncome()
66
	{
67
		return $this->getProfit() - $this->getProfitVat();
68
	}
69
70
	public function getEffectiveEvaluation()
71
	{
72
		if ($this->getPurchaseAmount() > 0) {
73
			return (pow(($this->getNetIncome() + $this->getAmount()) / $this->getPurchaseAmount(), 1/$this->length) - 1) * 100;
74
		} else {
75
			return 0;
76
		}
77
	}
78
79
	public function getTotalAmount()
80
	{
81
		return $this->amount + $this->getProfit();
82
	}
83
84
	public function getPurchaseAmount()
85
	{
86
		return $this->amount + $this->getCharge();
87
	}
88
89
	public function getProfitVat()
90
	{
91
		return $this->getProfit() * 0.15;
92
	}
93
94
	public function getCharge()
95
	{
96
		return $this->amount * ($this->rate->getCharge() - 1);
97
	}
98
99
    /**
100
     * Gets the value of amount.
101
     *
102
     * @return mixed
103
     */
104
    public function getAmount()
105
    {
106
        return $this->amount;
107
    }
108
109
    /**
110
     * Sets the value of amount.
111
     *
112
     * @param mixed $amount the amount
113
     *
114
     * @return self
115
     */
116
    public function setAmount($amount)
117
    {
118
        $this->amount = $amount;
119
120
        return $this;
121
    }
122
123
    /**
124
     * Gets the value of length.
125
     *
126
     * @return mixed
127
     */
128
    public function getLength()
129
    {
130
        return $this->length;
131
    }
132
133
    /**
134
     * Sets the value of length.
135
     *
136
     * @param mixed $length the length
137
     *
138
     * @return self
139
     */
140
    public function setLength($length)
141
    {
142
        $this->length = $length;
143
144
        return $this;
145
    }
146
147
    /**
148
     * Gets the value of rates.
149
     *
150
     * @return mixed
151
     */
152
    public function getRates()
153
    {
154
        return $this->rates;
155
    }
156
157
    /**
158
     * Sets the value of rates.
159
     *
160
     * @param mixed $rates the rates
161
     *
162
     * @return self
163
     */
164
    public function setRates($rates)
165
    {
166
        $this->rates = $rates;
167
168
        return $this;
169
    }
170
171
    /**
172
     * Gets the value of rate.
173
     *
174
     * @return mixed
175
     */
176
    public function getRate()
177
    {
178
        return $this->rate;
179
    }
180
181
    /**
182
     * Sets the value of rate.
183
     *
184
     * @param mixed $rate the rate
185
     *
186
     * @return self
187
     */
188
    public function setRate($rate)
189
    {
190
        $this->rate = $rate;
191
192
        return $this;
193
    }
194
}
195