Freelancer::apply()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Domain\Entities;
4
5
use App\Domain\Events\Freelancer\FreelancerAppliedForJob;
6
use App\Domain\Events\Freelancer\FreelancerRegistered;
7
use Doctrine\ORM\Mapping AS ORM;
8
use App\Domain\ValueObjects\Email;
9
use App\Domain\ValueObjects\Money;
10
use Ramsey\Uuid\UuidInterface;
11
12
/**
13
 * @ORM\Entity()
14
 */
15
final class Freelancer extends EntityWithEvents
16
{
17
    /**
18
     * @var Email
19
     * @ORM\Embedded(class = "App\Domain\ValueObjects\Email", columnPrefix = false)
20
     */
21
    private $email;
22
23
    /**
24
     * @var Money
25
     * @ORM\Embedded(class = "App\Domain\ValueObjects\Money")
26
     */
27
    private $hourRate;
28
29
    protected function __construct(UuidInterface $id, Email $email, Money $hourRate)
30
    {
31
        parent::__construct($id);
32
33
        $this->email = $email;
34
        $this->hourRate = $hourRate;
35
    }
36
37
    public static function register(UuidInterface $id, Email $email, Money $hourRate): Freelancer
38
    {
39
        $freelancer = new Freelancer($id, $email, $hourRate);
40
        $freelancer->record(new FreelancerRegistered($freelancer->getId()));
41
42
        return $freelancer;
43
    }
44
45
    /**
46
     * @param Job $job
47
     * @param string $coverLetter
48
     * @throws \App\Exceptions\Job\SameFreelancerProposalException
49
     */
50
    public function apply(Job $job, string $coverLetter)
51
    {
52
        $job->addProposal($this, $this->hourRate, $coverLetter);
53
54
        $this->record(new FreelancerAppliedForJob($this->getId(), $job->getId()));
55
    }
56
57
    public function equals(Freelancer $other): bool
58
    {
59
        return $this->id->equals($other->id);
60
    }
61
}