AccountOverviews::add()   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 1
dl 0
loc 3
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