Skip to content

Instantly share code, notes, and snippets.

@adelf

adelf/1.php Secret

Last active January 5, 2019 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adelf/a3c8a88879c1a200122ca1dd5030ba9d to your computer and use it in GitHub Desktop.
Save adelf/a3c8a88879c1a200122ca1dd5030ba9d to your computer and use it in GitHub Desktop.
Domain
<?php
final class Proposal
{
/** @var Freelancer */
private $freelancer;
/** @var Money */
private $hourRate;
/** @var string */
private $coverLetterMessage;
public function __construct(Freelancer $freelancer, Money $hourRate, string $coverLetterMessage)
{
$this->freelancer = $freelancer;
$this->hourRate = $hourRate;
$this->coverLetterMessage = $coverLetterMessage;
}
}
final class Freelancer
{
/** @var Email */
private $email;
/** @var Money */
private $hourRate;
public function __construct(Email $email, Money $hourRate)
{
$this->email = $email;
$this->hourRate = $hourRate;
}
public function makeProposal(string $coverLetterMessage): Proposal
{
return new Proposal($this, $this->hourRate, $coverLetterMessage);
}
}
final class Job
{
/** @var Customer */
private $customer;
/** @var JobDescription */
private $description;
/** @var Proposal[] */
private $proposals;
/** @var int */
private $proposalsLimit;
private function __construct(Customer $customer, JobDescription $description)
{
$this->customer = $customer;
$this->description = $description;
$this->proposals = [];
$this->proposalsLimit = 0;
}
public static function post(Customer $customer, JobDescription $description): Job
{
return new Job($customer, $description);
}
public function newProposal(Freelancer $freelancer, string $coverLetterMessage)
{
$this->proposals[] = $freelancer->makeProposal($coverLetterMessage);
}
}
<?php
final class Proposal
{
/** @var Freelancer */
private $freelancer;
/** @var Money */
private $hourRate;
/** @var string */
private $coverLetterMessage;
public function __construct(Freelancer $freelancer, Money $hourRate, string $coverLetterMessage)
{
$this->freelancer = $freelancer;
$this->hourRate = $hourRate;
$this->coverLetterMessage = $coverLetterMessage;
}
}
final class Freelancer
{
/** @var Email */
private $email;
/** @var Money */
private $hourRate;
public function __construct(Email $email, Money $hourRate)
{
$this->email = $email;
$this->hourRate = $hourRate;
}
public function apply(Job $job, string $coverLetterMessage)
{
$job->newProposal(new Proposal($this, $this->hourRate, $coverLetterMessage));
}
}
final class Job
{
/** @var Customer */
private $customer;
/** @var JobDescription */
private $description;
/** @var Proposal[] */
private $proposals;
/** @var int */
private $proposalsLimit;
private function __construct(Customer $customer, JobDescription $description)
{
$this->customer = $customer;
$this->description = $description;
$this->proposals = [];
$this->proposalsLimit = 0;
}
public static function post(Customer $customer, JobDescription $description): Job
{
return new Job($customer, $description);
}
public function addProposal(Proposal $proposal)
{
$this->proposals[] = $proposal;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment