MagicIsset::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 31
c 0
b 0
f 0
ccs 17
cts 17
cp 1
rs 9.424
cc 2
nc 2
nop 4
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
6
7
use InvalidArgumentException;
8
use Laminas\Code\Generator\ParameterGenerator;
9
use Laminas\Code\Generator\PropertyGenerator;
10
use ProxyManager\Generator\MagicMethodGenerator;
11
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
12
use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
13
use ReflectionClass;
14
15
/**
16
 * Magic `__isset` method for lazy loading value holder objects
17
 */
18
class MagicIsset extends MagicMethodGenerator
19
{
20
    /**
21
     * Constructor
22
     *
23
     * @throws InvalidArgumentException
24
     */
25
    public function __construct(
26
        ReflectionClass $originalClass,
27
        PropertyGenerator $initializerProperty,
28 1
        PropertyGenerator $valueHolderProperty,
29
        PublicPropertiesMap $publicProperties
30
    ) {
31
        parent::__construct($originalClass, '__isset', [new ParameterGenerator('name')]);
32
33
        $initializer = $initializerProperty->getName();
34 1
        $valueHolder = $valueHolderProperty->getName();
35
        $callParent  = '';
36 1
37 1
        if (! $publicProperties->isEmpty()) {
38 1
            $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n"
39
                . '    return isset($this->' . $valueHolder . '->$name);'
40 1
                . "\n}\n\n";
41 1
        }
42 1
43 1
        $callParent .= PublicScopeSimulator::getPublicAccessSimulationCode(
44
            PublicScopeSimulator::OPERATION_ISSET,
45
            'name',
46 1
            null,
47 1
            $valueHolderProperty
48 1
        );
49 1
50 1
        $this->setBody(
51
            '$this->' . $initializer . ' && $this->' . $initializer
52
            . '->__invoke($this->' . $valueHolder . ', $this, \'__isset\', array(\'name\' => $name), $this->'
53 1
            . $initializer . ');' . "\n\n" . $callParent
54 1
        );
55 1
    }
56
}
57