MagicSleep   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 19
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 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