ClosureMapping   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

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

4 Methods

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