/vendor/phpunit/php-code-coverage/tests/_files/BankAccount.php

https://bitbucket.org/alan_cordova/api-sb-map · PHP · 33 lines · 27 code · 6 blank · 0 comment · 2 complexity · 1fa57c931da01a8107b82bcf4b1fb15c MD5 · raw file

  1. <?php
  2. class BankAccount
  3. {
  4. protected $balance = 0;
  5. public function getBalance()
  6. {
  7. return $this->balance;
  8. }
  9. protected function setBalance($balance)
  10. {
  11. if ($balance >= 0) {
  12. $this->balance = $balance;
  13. } else {
  14. throw new RuntimeException;
  15. }
  16. }
  17. public function depositMoney($balance)
  18. {
  19. $this->setBalance($this->getBalance() + $balance);
  20. return $this->getBalance();
  21. }
  22. public function withdrawMoney($balance)
  23. {
  24. $this->setBalance($this->getBalance() - $balance);
  25. return $this->getBalance();
  26. }
  27. }