| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Domain\Entities; |
||
| 4 | |||
| 5 | use App\Exceptions\Job\SameFreelancerProposalException; |
||
| 6 | use Doctrine\ORM\Mapping AS ORM; |
||
| 7 | use App\Domain\ValueObjects\Money; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * @ORM\Entity() |
||
| 11 | */ |
||
| 12 | final class Proposal |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var int |
||
| 16 | * @ORM\Id |
||
| 17 | * @ORM\Column(type="integer", unique=true) |
||
| 18 | * @ORM\GeneratedValue(strategy="AUTO") |
||
| 19 | */ |
||
| 20 | private $id; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 21 | |||
| 22 | /** |
||
| 23 | * @ORM\ManyToOne(targetEntity="Job", inversedBy="proposals") |
||
| 24 | * @ORM\JoinColumn(name="job_id", referencedColumnName="id") |
||
| 25 | */ |
||
| 26 | private $job; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var Freelancer |
||
| 30 | * @ORM\ManyToOne(targetEntity="App\Domain\Entities\Freelancer") |
||
| 31 | * @ORM\JoinColumn(nullable=false) |
||
| 32 | */ |
||
| 33 | private $freelancer; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var Money |
||
| 37 | * @ORM\Embedded(class = "App\Domain\ValueObjects\Money") |
||
| 38 | */ |
||
| 39 | private $hourRate; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var string |
||
| 43 | * @ORM\Column(type="string") |
||
| 44 | */ |
||
| 45 | private $coverLetter; |
||
| 46 | |||
| 47 | public function __construct(Job $job, Freelancer $freelancer, Money $hourRate, string $coverLetter) |
||
| 48 | { |
||
| 49 | $this->job = $job; |
||
| 50 | $this->freelancer = $freelancer; |
||
| 51 | $this->hourRate = $hourRate; |
||
| 52 | $this->coverLetter = $coverLetter; |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param \App\Domain\Entities\Proposal $other |
||
| 57 | * @throws SameFreelancerProposalException |
||
| 58 | */ |
||
| 59 | public function checkCompatibility(Proposal $other) |
||
| 60 | { |
||
| 61 | if ($this->freelancer->equals($other->freelancer)) { |
||
| 62 | throw new SameFreelancerProposalException(); |
||
| 63 | } |
||
| 64 | } |
||
| 65 | } |