MagicIsset   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 35 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\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\AccessInterceptorValueHolder\MethodGenerator\Util\InterceptorGenerator;
12
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
13
use ProxyManager\ProxyGenerator\Util\GetMethodIfExists;
14
use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
15
use ReflectionClass;
16
17
/**
18
 * Magic `__isset` for method interceptor value holder objects
19
 */
20
class MagicIsset extends MagicMethodGenerator
21
{
22
    /**
23
     * Constructor
24
     *
25
     * @throws InvalidArgumentException
26
     */
27
    public function __construct(
28
        ReflectionClass $originalClass,
29 1
        PropertyGenerator $valueHolder,
30
        PropertyGenerator $prefixInterceptors,
31
        PropertyGenerator $suffixInterceptors,
32
        PublicPropertiesMap $publicProperties
33
    ) {
34
        parent::__construct($originalClass, '__isset', [new ParameterGenerator('name')]);
35
36 1
        $parent          = GetMethodIfExists::get($originalClass, '__isset');
37
        $valueHolderName = $valueHolder->getName();
38 1
39 1
        $callParent = PublicScopeSimulator::getPublicAccessSimulationCode(
40
            PublicScopeSimulator::OPERATION_ISSET,
41 1
            'name',
42 1
            'value',
43 1
            $valueHolder,
44 1
            'returnValue'
45 1
        );
46 1
47
        if (! $publicProperties->isEmpty()) {
48
            $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n"
49 1
                . '    $returnValue = isset($this->' . $valueHolderName . '->$name);'
50 1
                . "\n} else {\n    " . $callParent . "\n}\n\n";
51 1
        }
52 1
53
        $this->setBody(InterceptorGenerator::createInterceptedMethodBody(
54
            $callParent,
55 1
            $this,
56 1
            $valueHolder,
57 1
            $prefixInterceptors,
58 1
            $suffixInterceptors,
59 1
            $parent
60 1
        ));
61 1
    }
62
}
63