DefaultAttributeFactory::createCollection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Inspirum\Balikobot\Model\Attribute;
6
7
use function array_map;
8
use function trim;
9
10
final class DefaultAttributeFactory implements AttributeFactory
11
{
12
    /** @inheritDoc */
13 3
    public function create(array $data): Attribute
14
    {
15 3
        return new DefaultAttribute(
16 3
            trim($data['name']),
17 3
            $data['data_type'],
18 3
            (string) $data['max_length'],
19 3
        );
20
    }
21
22
    /** @inheritDoc */
23 3
    public function createCollection(string $carrier, array $data): AttributeCollection
24
    {
25 3
        return new DefaultAttributeCollection(
26 3
            $carrier,
27 3
            array_map(fn (array $attribute): Attribute => $this->create($attribute), $data['attributes'] ?? []),
28 3
        );
29
    }
30
}
31