Last active
October 31, 2017 18:20
-
-
Save spolischook/f7f2e774174c97d99e39719316bba5a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Transaction | |
{ | |
private $from; | |
private $to; | |
private $amount; | |
} | |
class Wallet | |
{ | |
private $amount; | |
public function getPayment(Wallet $wallet, int $amount): Transaction | |
{ | |
if ($amount > $wallet->getAmount()) { | |
thow new UnreachebleBalance($wallet); | |
} | |
$wallet->minusAmount($amount); | |
$this->plusAmount($amount); | |
return new Transaction($wallet, $this, $amount); | |
} | |
} | |
class Controller | |
{ | |
public function paymentAction(Wallet $form, Wallet $to, $amount) | |
{ | |
$transaction = $to->getPayment($from, $amount); | |
$this->em->persist($transaction); | |
$this->em->flush(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment