LazyLoadingMock::getWrappedValueHolderValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManagerTestAsset;
6
7
use BadMethodCallException;
8
use ProxyManager\Proxy\GhostObjectInterface;
9
use ProxyManager\Proxy\VirtualProxyInterface;
10
11
/**
12
 * Base test class to catch instantiations of lazy loading objects
13
 *
14
 * @author Marco Pivetta <[email protected]>
15
 * @license MIT
16
 */
17
class LazyLoadingMock implements VirtualProxyInterface, GhostObjectInterface
18
{
19
    /**
20
     * @var callable
21
     */
22
    public $initializer;
23
24
    /**
25
     * @param callable $initializer
26
     *
27
     * @return static
28
     */
29
    public static function staticProxyConstructor($initializer) : self
30
    {
31
        $instance = new static();
32
33
        $instance->initializer = $initializer;
34
35
        return $instance;
36
    }
37
38
    public function setProxyInitializer(\Closure $initializer = null) : void
39
    {
40
        $this->initializer = $initializer;
41
    }
42
43
    public function getProxyInitializer() : ?\Closure
44
    {
45
        return $this->initializer;
46
    }
47
48
    public function initializeProxy() : bool
49
    {
50
        // empty (on purpose)
51
        return true;
52
    }
53
54
    public function isProxyInitialized() : bool
55
    {
56
        return true;
57
    }
58
59
    /**
60
     * {@inheritDoc}
61
     *
62
     * @throws BadMethodCallException
63
     */
64
    public function getWrappedValueHolderValue() : ?object
65
    {
66
        // we're not supposed to call this
67
        throw new BadMethodCallException('Not implemented');
68
    }
69
}
70