MapTransform::name()   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 1
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Hydration\Mapping\Transform;
4
5
use Stratadox\HydrationMapping\Mapping;
6
use function array_map;
7
8
final class MapTransform implements Mapping
9
{
10
    /** @var string */
11
    private $key;
12
    /** @var Mapping */
13
    private $mapping;
14
15
    private function __construct(string $key, Mapping $mapping)
16
    {
17
        $this->key = $key;
18
        $this->mapping = $mapping;
19
    }
20
21
    public static function withKey(string $key, Mapping $mapping): Mapping
22
    {
23
        return new self($key, $mapping);
24
    }
25
26
    public function name(): string
27
    {
28
        return $this->mapping->name();
29
    }
30
31
    public function value(array $data, $owner = null)
32
    {
33
        $data = array_map(function ($value): array {
34
            return [$this->key => $value];
35
        }, $data);
36
        return $this->mapping->value($data, $owner);
37
    }
38
}
39