PrimitiveMapping   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

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

4 Methods

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