MagicSleep::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 19
c 0
b 0
f 0
ccs 10
cts 10
cp 1
rs 9.6333
cc 2
nc 2
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 `__sleep` for lazy loading ghost objects
15
 */
16
class MagicSleep 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, '__sleep');
27
28 2
        $parent = GetMethodIfExists::get($originalClass, '__sleep');
29
30 2
        $callParent = $parent ? '$returnValue = & parent::__sleep();' : '$returnValue = array_keys((array) $this);';
31
32 2
        $this->setBody(InterceptorGenerator::createInterceptedMethodBody(
33
            $callParent,
34 2
            $this,
35 2
            $prefixInterceptors,
36 2
            $suffixInterceptors,
37 2
            $parent
38 2
        ));
39 2
    }
40
}
41