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