-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckingAccount.php
122 lines (97 loc) · 2.37 KB
/
CheckingAccount.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
use exception\InsufficientBalanceException;
// require 'exception\InsufficientBalanceException.php';
class CheckingAccount {
private $holder;
public $agency;
private $number;
private $balance;
public static $totalOfAccounts;
public static $operationTax;
public $withdrawalsNotAlloweds;
public static $operationNotRealized;
public function __construct($holder, $agency, $number, $balance)
{
$this->holder = $holder;
$this->agency = $agency;
$this->number = $number;
$this->balance = $balance;
self::$totalOfAccounts++;
try {
if(self::$totalOfAccounts < 1) {
throw new \Exception("The value is smaller than 0");
}
self::$operationTax =30/ self::$totalOfAccounts;
} catch(\Exception $e) {
echo $e->getMessage();
exit;
}
}
public function __get($attribute)
{
Validation::protectAttribute($attribute);
return $this->$attribute;
}
public function __set($attribute, $value)
{
Validation::protectAttribute($attribute);
$this->$attribute = $value;
}
public function withdraw($value)
{
Validation::verifyNumeric($value);
if($value > $this->balance) {
throw new InsufficientBalanceException("There is no sufficient money in your account!!!", $value, $this->balance);
}
$this->balance = $this->balance - $value;
return $this;
}
public function deposit($value)
{
Validation::verifyNumeric($value);
$this->balance = $this->balance + $value;
return $this;
}
public function transfer($value, CheckingAccount $account)
{
try {
$file = new FileReading("logTransfer.txt");
$file->openFile();
$file->writeFile();
Validation::verifyNumeric($value);
if($value <= 0) {
throw new \Exception("The value should to be bigger than 0");
}
$this->sacar($value);
$contaCorrente->deposit($value);
$file->closeFile();
return $this;
} catch(\Exception $e) {
self::$operationNotRealized++;
throw new exception\OperationNotRealizedException("Operation not realized", 55, $e);
} finally {
echo "finally";
$file->closeFile();
}
}
public function formatBalance()
{
return "R$" . number_format($this->balance, 2, ",", ".");
}
public function __toString()
{
return $this->balance;
}
public function setNumber($number)
{
return $this->number;
}
public function getHolder()
{
return $this->holder;
}
public function getBalance()
{
return $this->formatBalance();
}
}