LazyLoadingMock   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 53
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A staticProxyConstructor() 0 8 1
A setProxyInitializer() 0 4 1
A getProxyInitializer() 0 4 1
A initializeProxy() 0 5 1
A isProxyInitialized() 0 4 1
A getWrappedValueHolderValue() 0 5 1
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