AccountOverviews::forVisitor()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 8
rs 10
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