MagicClone::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

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 2
nc 1
nop 3
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator;
6
7
use Laminas\Code\Generator\PropertyGenerator;
8
use ProxyManager\Generator\MagicMethodGenerator;
9
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Util\InterceptorGenerator;
10
use ProxyManager\ProxyGenerator\Util\GetMethodIfExists;
11
use ReflectionClass;
12
13
/**
14
 * Magic `__clone` for lazy loading ghost objects
15
 */
16
class MagicClone extends MagicMethodGenerator
17
{
18
    /**
19
     * Constructor
20
     */
21
    public function __construct(
22
        ReflectionClass $originalClass,
23 2
        PropertyGenerator $prefixInterceptors,
24
        PropertyGenerator $suffixInterceptors
25
    ) {
26
        parent::__construct($originalClass, '__clone');
27
28 2
        $parent = GetMethodIfExists::get($originalClass, '__clone');
29
30 2
        $this->setBody(InterceptorGenerator::createInterceptedMethodBody(
31
            $parent ? '$returnValue = parent::__clone();' : '$returnValue = null;',
32 2
            $this,
33 2
            $prefixInterceptors,
34 2
            $suffixInterceptors,
35 2
            $parent
36 2
        ));
37 2
    }
38
}
39