MyProxiedClass   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 7
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A sayHello() 0 4 1
1
<?php
2
3
namespace StaticAnalysis\LazyLoadingValueHolder;
4
5
use ProxyManager\Factory\LazyLoadingValueHolderFactory;
6
use ProxyManager\Proxy\LazyLoadingInterface;
7
8
require_once __DIR__ . '/../../vendor/autoload.php';
9
10
class MyProxiedClass
11
{
12
    public function sayHello() : string
13
    {
14
        return 'Hello!';
15
    }
16
}
17
18
(static function () : void {
19
    echo (new LazyLoadingValueHolderFactory())
20
        ->createProxy(
21
            MyProxiedClass::class,
22
            static function (
23
                ?object & $instance,
24
                LazyLoadingInterface $proxy,
25
                string $method,
26
                array $parameters,
27
                ?\Closure & $initializer
28
            ) : bool {
29
                $instance    = new MyProxiedClass();
30
                $initializer = null; // disable initialization
31
32
                return true;
33
            }
34
        )
35
        ->sayHello();
36
37
    $valueHolder = (new LazyLoadingValueHolderFactory())
38
        ->createProxy(MyProxiedClass::class, static function (
39
            ?object & $wrappedObject,
40
            LazyLoadingInterface $proxy,
41
            string $method,
42
            array $parameters,
43
            ?\Closure & $initializer
44
        ) : bool {
45
            $initializer   = null; // disable initialization
46
            $wrappedObject = new MyProxiedClass();
47
48
            return true;
49
        });
50
51
    $valueHolder->initializeProxy();
52
53
    $wrappedValue = $valueHolder->getWrappedValueHolderValue();
54
55
    assert(null !== $wrappedValue);
56
57
    echo $wrappedValue->sayHello();
58
59
    $valueHolder->setProxyInitializer(static function (
60
        ?object & $instance,
61
        LazyLoadingInterface $proxy,
62
        string $method,
63
        array $parameters,
64
        ?\Closure & $initializer
65
    ) : bool {
66
        $instance    = new MyProxiedClass();
67
        $initializer = null; // disable initialization
68
69
        return true;
70
    });
71
})();
72