Yaffs site version 1.1
[yaffs-website] / vendor / phpunit / phpunit / tests / _files / BankAccount.php
1 <?php
2 /*
3  * This file is part of PHPUnit.
4  *
5  * (c) Sebastian Bergmann <sebastian@phpunit.de>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 class BankAccountException extends RuntimeException
12 {
13 }
14
15 /**
16  * A bank account.
17  *
18  * @since      Class available since Release 2.3.0
19  */
20 class BankAccount
21 {
22     /**
23      * The bank account's balance.
24      *
25      * @var float
26      */
27     protected $balance = 0;
28
29     /**
30      * Returns the bank account's balance.
31      *
32      * @return float
33      */
34     public function getBalance()
35     {
36         return $this->balance;
37     }
38
39     /**
40      * Sets the bank account's balance.
41      *
42      * @param float $balance
43      *
44      * @throws BankAccountException
45      */
46     protected function setBalance($balance)
47     {
48         if ($balance >= 0) {
49             $this->balance = $balance;
50         } else {
51             throw new BankAccountException;
52         }
53     }
54
55     /**
56      * Deposits an amount of money to the bank account.
57      *
58      * @param float $balance
59      *
60      * @throws BankAccountException
61      */
62     public function depositMoney($balance)
63     {
64         $this->setBalance($this->getBalance() + $balance);
65
66         return $this->getBalance();
67     }
68
69     /**
70      * Withdraws an amount of money from the bank account.
71      *
72      * @param float $balance
73      *
74      * @throws BankAccountException
75      */
76     public function withdrawMoney($balance)
77     {
78         $this->setBalance($this->getBalance() - $balance);
79
80         return $this->getBalance();
81     }
82 }