Visitor   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A id() 0 3 1
A visit() 0 14 2
A openAccount() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\CardGame\Visiting;
4
5
use DateTimeInterface;
6
use Stratadox\CardGame\Account\AccountId;
7
use Stratadox\CardGame\Account\PlayerAccount;
8
use Stratadox\CardGame\DomainEventRecorder;
9
use Stratadox\CardGame\DomainEventRecording;
10
11
final class Visitor implements DomainEventRecorder
12
{
13
    use DomainEventRecording;
14
15
    private $id;
16
    private $visitedPages = [];
17
18
    public function __construct(VisitorId $id)
19
    {
20
        $this->id = $id;
21
    }
22
23
    public function id(): VisitorId
24
    {
25
        return $this->id;
26
    }
27
28
    public function openAccount(AccountId $playerId): PlayerAccount
29
    {
30
        return PlayerAccount::fromVisitor($this->id, $playerId);
31
    }
32
33
    public function visit(
34
        string $page,
35
        DateTimeInterface $when,
36
        string $source
37
    ): void {
38
        $isFirstVisit = !isset($this->visitedPages[$page]);
39
        if ($isFirstVisit) {
40
            $this->visitedPages[$page] = $when;
41
        }
42
        $this->events[] = new VisitedPage(
43
            $this->id,
44
            $page,
45
            $source,
46
            $isFirstVisit
47
        );
48
    }
49
}
50