Passed
Push — master ( 4327f5...645913 )
by Chris
03:00
created

Delegate::checkIn()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 7
rs 9.4285
ccs 4
cts 4
cp 1
crap 2
1
<?php
2
3
4
namespace ConferenceTools\Checkin\Domain\Model\Delegate;
5
6
use Carnage\Cqrs\Aggregate\AbstractAggregate;
7
use ConferenceTools\Checkin\Domain\Event\Delegate\DelegateCheckedIn;
8
use ConferenceTools\Checkin\Domain\Event\Delegate\DelegateInformationUpdated;
9
use ConferenceTools\Checkin\Domain\Event\Delegate\DelegateRegistered;
10
use ConferenceTools\Checkin\Domain\ValueObject\DelegateInfo;
11
use ConferenceTools\Checkin\Domain\ValueObject\Ticket;
12
13
class Delegate extends AbstractAggregate
14
{
15
    private $id;
16
    private $delegateInfo;
17
    private $checkedIn = false;
18
19 3
    public function getId()
20
    {
21 3
        return $this->id;
22
    }
23
24 1
    public static function register(
25
        string $id,
26
        DelegateInfo $delegateInfo,
27
        Ticket $ticket,
28
        string $purchaserEmail
29
    ) {
30 1
        $instance = new static();
31 1
        $instance->apply(new DelegateRegistered($id, $delegateInfo, $ticket, $purchaserEmail));
32
33 1
        return $instance;
34
    }
35
36 4
    protected function applyDelegateRegistered(DelegateRegistered $event)
37
    {
38 4
        $this->id = $event->getDelegateId();
39 4
        $this->delegateInfo = $event->getDelegateInfo();
40 4
    }
41
42 1
    public function updateDelegateInformation(DelegateInfo $delegateInfo)
43
    {
44 1
        $this->apply(new DelegateInformationUpdated($this->id, $delegateInfo));
45 1
    }
46
47 1
    protected function applyDelegateInformationUpdated(DelegateInformationUpdated $event)
48
    {
49 1
        $this->delegateInfo = $event->getDelegateInfo();
50 1
    }
51
52 2
    public function checkIn()
53
    {
54 2
        if ($this->checkedIn) {
55 1
            throw new \DomainException('Delegate has already been checked in');
56
        }
57
58 1
        $this->apply(new DelegateCheckedIn($this->id));
59 1
    }
60
61 2
    protected function applyDelegateCheckedIn(DelegateCheckedIn $event)
62
    {
63 2
        $this->checkedIn = true;
64
    }
65
}