Test Setup Failed
Push — master ( a63fa0...36623d )
by Jesse
04:59
created

MatchProposal::begin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\CardGame\ReadModel\Proposal;
4
5
use DateTimeInterface;
6
use Stratadox\CardGame\Account\AccountId;
7
use Stratadox\CardGame\Match\MatchId;
8
use Stratadox\CardGame\Proposal\ProposalId;
9
10
final class MatchProposal
11
{
12
    /** @var ProposalId */
13
    private $id;
14
    /** @var AccountId */
15
    private $from;
16
    /** @var AccountId */
17
    private $to;
18
    /** @var DateTimeInterface */
19
    private $validUntil;
20
    /** @var bool */
21
    private $accepted = false;
22
    /** @var null|MatchId */
23
    private $match;
24
25
    public function __construct(
26
        ProposalId $id,
27
        AccountId $from,
28
        AccountId $to,
29
        DateTimeInterface $validUntil
30
    ) {
31
        $this->id = $id;
32
        $this->from = $from;
33
        $this->to = $to;
34
        $this->validUntil = $validUntil;
35
    }
36
37
    public function id(): ProposalId
38
    {
39
        return $this->id;
40
    }
41
42
    public function canBeAcceptedBy(AccountId $player, DateTimeInterface $when): bool
43
    {
44
        return !$this->accepted
45
            && $this->to->is($player)
46
            && $when <= $this->validUntil;
47
    }
48
49
    public function wasProposedBy(AccountId $account): bool
50
    {
51
        return $this->from->is($account);
52
    }
53
54
    public function wasProposedTo(AccountId $account): bool
55
    {
56
        return $this->to->is($account);
57
    }
58
59
    public function hasBeenAccepted(): bool
60
    {
61
        return $this->accepted;
62
    }
63
64
    public function accept(): void
65
    {
66
        $this->accepted = true;
67
    }
68
69
    public function begin(MatchId $match): void
70
    {
71
        $this->match = $match;
72
    }
73
}
74