Passed
Push — master ( 1ecf3f...1524c7 )
by Jesse
02:53
created

ClosureResult::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stratadox\Hydration\Mapping\Property\Dynamic;
6
7
use Closure;
8
use Stratadox\Hydration\MapsProperty;
9
10
/**
11
 * Maps to the result of a closure that runs against the input data.
12
 *
13
 * @package Stratadox\Hydrate
14
 * @author Stratadox
15
 */
16
class ClosureResult implements MapsProperty
17
{
18
    private $property;
19
    private $function;
20
21
    private function __construct(string $property, Closure $function)
22
    {
23
        $this->property = $property;
24
        $this->function = $function;
25
    }
26
27
    public static function inProperty(string $name, Closure $function) : MapsProperty
28
    {
29
        return new static($name, $function);
30
    }
31
32
    public function name() : string
33
    {
34
        return $this->property;
35
    }
36
37
    public function value(array $data, $owner = null)
38
    {
39
        return $this->function->call($this, $data);
40
    }
41
}
42