Last active
June 7, 2018 10:48
-
-
Save viniciusss/ff040eaa509fbb743c85c5cb7458231d 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 | |
namespace App\Student; | |
class BoletoPayment implements Payment | |
{ | |
// todo | |
} |
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 | |
namespace App\Student; | |
class CreditCardPayment implements Payment | |
{ | |
// todo | |
} |
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 | |
namespace App\Student; | |
interface Payment | |
{ | |
} |
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 | |
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(); | |
} | |
} |
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 | |
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