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

ClosureResult   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

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