MagicSleep::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

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