Failed Conditions
Pull Request — master (#6649)
by Marco
62:58
created

LazyPropertyMap   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 22
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A __get() 0 6 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Doctrine\ORM\Internal\Hydration\Cache;
5
6
/**
7
 * Concept taken from ocramius/lazy-map
8
 *
9
 * @link https://github.com/Ocramius/LazyMap/blob/1.0.0/src/LazyMap/CallbackLazyMap.php
10
 * @internal do not use: internal class only
11
 */
12
final class LazyPropertyMap
13
{
14
    public function __construct(callable $instantiate)
15
    {
16
        // Note: the reason why we use dynamic access to create a private-ish property is
17
        //       that we do not want this property to be statically defined. If that
18
        //       happens, then a consumer of `__get` may access it, and that's no good
19
        $this->{self::class . "\0callback"} = $instantiate;
20
    }
21
22
    /**
23
     * @param string $name
24
     *
25
     * @return mixed
26
     */
27
    public function __get(string $name)
28
    {
29
        $this->$name = ($this->{self::class . "\0callback"})($name);
30
31
        return $this->$name;
32
    }
33
}
34