Skip to content

Instantly share code, notes, and snippets.

@adelf adelf/1.php Secret
Last active Jan 5, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.