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

MatchProposal   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 62
rs 10
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A hasBeenAccepted() 0 3 1
A wasProposedBy() 0 3 1
A begin() 0 3 1
A canBeAcceptedBy() 0 5 3
A id() 0 3 1
A accept() 0 3 1
A wasProposedTo() 0 3 1
A __construct() 0 10 1
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