MagicGet::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 29
c 0
b 0
f 0
ccs 16
cts 16
cp 1
rs 9.456
cc 2
nc 2
nop 3
crap 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