Constructor::__construct()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
c 0
b 0
f 0
rs 8.8571
cc 1
eloc 22
nc 1
nop 5
1
<?php
2
3
namespace Isolate\LazyObjects\Proxy\Adapter\OcramiusProxyManager\MethodGenerator;
4
5
use ProxyManager\Generator\MethodGenerator;
6
use ProxyManager\Generator\ParameterGenerator;
7
use ReflectionClass;
8
use ReflectionProperty;
9
use Zend\Code\Generator\PropertyGenerator;
10
11
class Constructor extends MethodGenerator
12
{
13
    /**
14
     * Constructor
15
     */
16
    public function __construct(
17
        ReflectionClass $originalClass,
18
        PropertyGenerator $wrappedObjectProperty,
19
        PropertyGenerator $lazyPropertiesProperty,
20
        PropertyGenerator $methodReplacementsProperty,
21
        PropertyGenerator $initializerProperty
22
    ) {
23
        parent::__construct('__construct');
24
25
        $lazyPropertiesArg = new ParameterGenerator('lazyProperties');
26
        $lazyPropertiesArg->setDefaultValue([]);
27
        $lazyPropertiesArg->setType('array');
28
29
        $methodReplacementsArg = new ParameterGenerator('methodReplacements');
30
        $methodReplacementsArg->setDefaultValue([]);
31
        $methodReplacementsArg->setType('array');
32
33
        $this->setParameter(new ParameterGenerator('wrappedObject'));
34
        $this->setParameter($lazyPropertiesArg);
35
        $this->setParameter($methodReplacementsArg);
36
37
        $this->setBody(
38
              '$this->' . $wrappedObjectProperty->getName() . " = \$wrappedObject;\n"
39
            . '$this->' . $lazyPropertiesProperty->getName() . " = \$lazyProperties;\n"
40
            . '$this->' . $methodReplacementsProperty->getName() . " = \$methodReplacements;\n"
41
            . '$this->' . $initializerProperty->getName() . " = new \\Isolate\\LazyObjects\\Object\\Property\\Initializer();\n"
42
            . '$this->' . $initializerProperty->getName() . "->initialize(\$this->" . $lazyPropertiesProperty->getName() . ", \"__construct\", \$this->" . $wrappedObjectProperty->getName() . ");\n"
43
        );
44
    }
45
}
46