MapTransform   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
dl 0
loc 29
rs 10
c 1
b 0
f 1
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 3 1
A value() 0 6 1
A __construct() 0 4 1
A withKey() 0 3 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