Board::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
/**
3
 *
4
 * This file is part of the Aggrego.
5
 * (c) Tomasz Kunicki <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 */
11
12
declare(strict_types = 1);
13
14
namespace Aggrego\FragmentedDataBoard\Board\Prototype;
15
16
use Aggrego\FragmentedDataBoard\Board\Metadata;
17
use Aggrego\FragmentedDataBoard\Board\Prototype\Shard\Collection;
18
use Aggrego\FragmentedDataBoard\Board\Prototype\Shard\Item;
19
use Aggrego\FragmentedDataBoard\Board\Shard\Collection as ShardsCollection;
20
use Aggrego\FragmentedDataBoard\Board\Shard\InitialItem;
21
use Aggrego\FragmentedDataBoard\Board\State;
22
use Aggrego\Domain\Board\Key;
23
use Aggrego\Domain\Board\Metadata as DomainMetadata;
24
use Aggrego\Domain\Board\Prototype\Board as BoardInterface;
25
use Aggrego\Domain\Profile\Profile;
26
use Traversable;
27
28
class Board implements BoardInterface
29
{
30
    /** @var Key */
31
    private $key;
32
33
    /** @var Profile */
34
    private $profile;
35
36
    /** @var Collection */
37
    private $shards;
38
39
    /** @var State  */
40
    private $state;
41
42
    public function __construct(Key $key, Profile $profile, State $state)
43
    {
44
        $this->key = $key;
45
        $this->profile = $profile;
46
        $this->shards = new Collection();
47
        $this->state = $state;
48
    }
49
50
    public function getKey(): Key
51
    {
52
        return $this->key;
53
    }
54
55
    public function getProfile(): Profile
56
    {
57
        return $this->profile;
58
    }
59
60
    public function getShards(): Traversable
61
    {
62
        return $this->shards->getIterator();
63
    }
64
65
    public function addShard(Key $key, Profile $shardProfile): void
66
    {
67
        $this->shards->add(new Item($shardProfile, $key));
68
    }
69
70
    public function getMetadata(): DomainMetadata
71
    {
72
        $shardsList = [];
73
        /** @var Item $item */
74
        foreach ($this->getShards() as $item) {
75
            $shardsList[] = new InitialItem($item->getProfile(), $item->getKey());
76
        }
77
78
        return new Metadata($this->state, new ShardsCollection($shardsList));
79
    }
80
}
81