Passed
Push — master ( 01c6a8...5a4258 )
by Jesse
09:00
created

Nested   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 3 1
A value() 0 4 1
A __construct() 0 4 1
A inKey() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Hydration\Mapping;
4
5
use Stratadox\HydrationMapping\Mapping;
6
7
final class Nested implements Mapping
8
{
9
    /** @var string */
10
    private $key;
11
    /** @var Mapping */
12
    private $mapping;
13
14
    private function __construct(string $key, Mapping $mapping)
15
    {
16
        $this->key = $key;
17
        $this->mapping = $mapping;
18
    }
19
20
    public static function inKey(string $key, Mapping $mapping): self
21
    {
22
        return new self($key, $mapping);
23
    }
24
25
    public function name(): string
26
    {
27
        return $this->mapping->name();
28
    }
29
30
    public function value(array $data, $owner = null)
31
    {
32
        AssertKey::exists($this, $data, $this->key);
33
        return $this->mapping->value($data[$this->key]);
34
    }
35
}
36