Skip to content

Instantly share code, notes, and snippets.

@spolischook
Last active October 31, 2017 18:20
Show Gist options
  • Save spolischook/f7f2e774174c97d99e39719316bba5a9 to your computer and use it in GitHub Desktop.
Save spolischook/f7f2e774174c97d99e39719316bba5a9 to your computer and use it in GitHub Desktop.
<?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