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

ClosureMapping::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
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