Passed
Push — master ( 1524c7...5ae88a )
by Jesse
02:33
created

HasOneProxy::inProperty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stratadox\Hydration\Mapping\Property\Relationship;
6
7
use Stratadox\Hydration\MapsProperty;
8
use Stratadox\Hydration\ProducesProxies;
9
10
/**
11
 * Maps a proxy to a has-one relation in an object property.
12
 *
13
 * @package Stratadox\Hydrate
14
 * @author Stratadox
15
 */
16
class HasOneProxy implements MapsProperty
17
{
18
    private $name;
19
    private $proxyBuilder;
20
21
    protected function __construct(
22
        string $name,
23
        ProducesProxies $proxyBuilder
24
    ) {
25
        $this->name = $name;
26
        $this->proxyBuilder = $proxyBuilder;
27
    }
28
29
    public static function inProperty(
30
        string $name,
31
        ProducesProxies $proxyBuilder
32
    ) : MapsProperty
33
    {
34
        return new static($name, $proxyBuilder);
35
    }
36
37
    /** @inheritdoc @return mixed|object */
38
    public function value(array $data, $owner = null)
39
    {
40
        return $this->proxyBuilder->createFor($owner, $this->name);
41
    }
42
43
    public function name() : string
44
    {
45
        return $this->name;
46
    }
47
}
48