Passed
Pull Request — 1.0.0 (#7)
by
unknown
08:21
created

IdCollection::toStringArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace StraTDeS\VO\Collection;
4
5
use StraTDeS\SharedKernel\Domain\Identity\Id;
6
use StraTDeS\SharedKernel\Tests\Unit\Domain\DomainEvent\IdStub;
7
8
class IdCollection extends AbstractCollection
9
{
10
    protected function itemClass(): string
11
    {
12
        return Id::class;
13
    }
14
15
    /** @return string[] */
16
    public function toStringArray(): array
17
    {
18
        return array_map(function (Id $id) {
19
            return $id->getHumanReadableId();
20
        }, $this->items);
21
    }
22
23
    /**
24
     * @param string[] $ids
25
     * @return self
26
     */
27
    public static function fromStringArray(array $ids): self
28
    {
29
        /** @var self $idCollection */
30
        $idCollection = self::create();
31
        foreach ($ids as $id) {
32
            $idCollection->add(IdStub::fromString($id));
33
        }
34
        return $idCollection;
35
    }
36
}
37