AccountOverviews   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A forVisitor() 0 8 3
A add() 0 3 1
A startEmpty() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\CardGame\ReadModel\Account;
4
5
use Stratadox\CardGame\Visiting\VisitorId;
6
7
class AccountOverviews
8
{
9
    /** @var AccountOverview[] */
10
    private $accounts = [];
11
12
    public static function startEmpty(): self
13
    {
14
        return new self();
15
    }
16
17
    public function add(AccountOverview $accountOverview): void
18
    {
19
        $this->accounts[] = $accountOverview;
20
    }
21
22
    /** @throws NoAccountForVisitor */
23
    public function forVisitor(VisitorId $visitor): AccountOverview
24
    {
25
        foreach ($this->accounts as $accountOverview) {
26
            if ($visitor->is($accountOverview->visitor())) {
27
                return $accountOverview;
28
            }
29
        }
30
        throw NoAccountForVisitor::withId($visitor);
31
    }
32
}
33