MagicClone::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 17
c 0
b 0
f 0
ccs 9
cts 9
cp 1
rs 9.7
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
6
7
use Laminas\Code\Generator\PropertyGenerator;
8
use ProxyManager\Generator\MagicMethodGenerator;
9
use ReflectionClass;
10
11
/**
12
 * Magic `__clone` for lazy loading value holder objects
13
 */
14
class MagicClone extends MagicMethodGenerator
15
{
16
    /**
17
     * Constructor
18
     */
19
    public function __construct(
20
        ReflectionClass $originalClass,
21 1
        PropertyGenerator $initializerProperty,
22
        PropertyGenerator $valueHolderProperty
23
    ) {
24
        parent::__construct($originalClass, '__clone');
25
26 1
        $initializer = $initializerProperty->getName();
27
        $valueHolder = $valueHolderProperty->getName();
28 1
29 1
        $this->setBody(
30
            '$this->' . $initializer . ' && $this->' . $initializer
31 1
            . '->__invoke($this->' . $valueHolder
32 1
            . ', $this, \'__clone\', array(), $this->' . $initializer . ');' . "\n\n"
33 1
            . '$this->' . $valueHolder . ' = clone $this->' . $valueHolder . ';'
34 1
        );
35 1
    }
36
}
37