1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- namespace SomeNamespace;
- class BankAccount
- {
- use BankAccountTrait;
- }
- trait BankAccountTrait {
- protected $balance = 0;
- public function getBalance()
- {
- return $this->balance;
- }
- protected function setBalance($balance)
- {
- if ($balance >= 0) {
- $this->balance = $balance;
- } else {
- throw new \RuntimeException;
- }
- }
- public function depositMoney($balance)
- {
- $this->setBalance($this->getBalance() + $balance);
- return $this->getBalance();
- }
- public function withdrawMoney($balance)
- {
- $this->setBalance($this->getBalance() - $balance);
- return $this->getBalance();
- }
- }
|