Skip to content

Instantly share code, notes, and snippets.

@viniciusss
Last active June 7, 2018 10:48
Show Gist options
  • Save viniciusss/ff040eaa509fbb743c85c5cb7458231d to your computer and use it in GitHub Desktop.
Save viniciusss/ff040eaa509fbb743c85c5cb7458231d to your computer and use it in GitHub Desktop.
<?php
namespace App\Student;
class BoletoPayment implements Payment
{
// todo
}
<?php
namespace App\Student;
class CreditCardPayment implements Payment
{
// todo
}
<?php
namespace App\Student;
interface Payment
{
}
<?php
namespace App\Student;
use Doctrine\Common\Collections\{ArrayCollection, Collection};
use DateTime;
class Student
{
protected $id;
protected $name;
/**
* @var Collection|Subscription[]
*/
protected $subscriptions;
public function __construct(int $id, string $name)
{
$this->id = $id;
$this->name = $name;
$this->subscriptions = new ArrayCollection();
}
public function subscribe(DateTime $expireAt)
{
$this->subscriptions->add(new Subscrption($expireAt));
}
/**
* @var Subscription[]
*/
public function getSubscriptions(): array
{
return $this->subscriptions->toArray();
}
}
<?php
namespace App\Student;
use DateTime;
use Doctrine\Common\Collections\{ArrayCollection, Collection};
class Subscription
{
/**
* @var DateTime
*/
protected $expireAt;
/**
* @var Collection|Payment[]
*/
protected $payments;
public function __construct(DateTime $expireAt)
{
$this->expireAt = $expireAt;
$this->payments = new ArrayCollection();
}
public function addPayment(string $type, array $data)
{
switch($type) {
case 'boleto':
$payment = new BoletoPayment($data['ournumber']); // etc, etc
break;
case 'creditcard':
$payment = new CreditCardPayment($data['cardnumber']); // etc, etc
break;
}
$this->payments->add($payment);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment