PlayerAccount::fromVisitor()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\CardGame\Account;
4
5
use DateTimeInterface;
6
use Stratadox\CardGame\DomainEventRecorder;
7
use Stratadox\CardGame\DomainEventRecording;
8
use Stratadox\CardGame\Proposal\MatchProposal;
9
use Stratadox\CardGame\Proposal\ProposalId;
10
use Stratadox\CardGame\Visiting\VisitorId;
11
12
final class PlayerAccount implements DomainEventRecorder
13
{
14
    use DomainEventRecording;
15
16
    private $id;
17
18
    private function __construct(AccountId $id, AccountEvent $creationEvent)
19
    {
20
        $this->id = $id;
21
        $this->events[] = $creationEvent;
22
    }
23
24
    public static function fromVisitor(VisitorId $visitor, AccountId $id): self
25
    {
26
        return new self($id, VisitorOpenedAnAccount::with($id, $visitor));
27
    }
28
29
    public function id(): AccountId
30
    {
31
        return $this->id;
32
    }
33
34
    public function proposeMatchTo(
35
        AccountId $player,
36
        DateTimeInterface $validUntil,
37
        ProposalId $proposalId
38
    ): MatchProposal {
39
        return new MatchProposal(
40
            $proposalId,
41
            $this->id,
42
            $player,
43
            $validUntil
44
        );
45
    }
46
}
47