Proxying::__load()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stratadox\Hydration\Proxying;
6
7
use function is_null;
8
use Stratadox\Hydration\LoadsProxiedObjects;
9
use Stratadox\Hydration\Proxy;
10
11
/**
12
 * Lazily loads proxy targets.
13
 *
14
 * @author Stratadox
15
 * @package Stratadox/Hydrate
16
 */
17
trait Proxying
18
{
19
    /** @var LoadsProxiedObjects */
20
    private $loader;
21
22
    /** @var object|null */
23
    private $instance;
24
25
    /** @return self */
26
    public function __load()
27
    {
28
        if (is_null($this->instance)) {
29
            /** @var Proxy $this */
30
            $this->instance = $this->loader->loadTheInstance();
0 ignored issues
show
Bug introduced by
Accessing instance on the interface Stratadox\Hydration\Proxy suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
Bug introduced by
Accessing loader on the interface Stratadox\Hydration\Proxy suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
31
        }
32
        return $this->instance;
33
    }
34
}
35