MagicGet   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 5
dl 0
loc 35
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 29 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\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\AccessInterceptorScopeLocalizer\MethodGenerator\Util\InterceptorGenerator;
12
use ProxyManager\ProxyGenerator\Util\GetMethodIfExists;
13
use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
14
use ReflectionClass;
15
16
/**
17
 * Magic `__get` for lazy loading ghost objects
18
 */
19
class MagicGet extends MagicMethodGenerator
20
{
21
    /**
22
     * @throws InvalidArgumentException
23
     */
24
    public function __construct(
25
        ReflectionClass $originalClass,
26
        PropertyGenerator $prefixInterceptors,
27 2
        PropertyGenerator $suffixInterceptors
28
    ) {
29
        parent::__construct($originalClass, '__get', [new ParameterGenerator('name')]);
30
31
        $parent = GetMethodIfExists::get($originalClass, '__get');
32 2
33
        $callParent = '$returnValue = & parent::__get($name);';
34 2
35
        if (! $parent) {
36 2
            $callParent = PublicScopeSimulator::getPublicAccessSimulationCode(
37
                PublicScopeSimulator::OPERATION_GET,
38 2
                'name',
39 1
                null,
40 1
                null,
41 1
                'returnValue'
42 1
            );
43 1
        }
44 1
45
        $this->setBody(InterceptorGenerator::createInterceptedMethodBody(
46
            $callParent,
47
            $this,
48 2
            $prefixInterceptors,
49 2
            $suffixInterceptors,
50 2
            $parent
51 2
        ));
52 2
    }
53
}
54