StaticProxyConstructor   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 4
dl 0
loc 30
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 21 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator;
6
7
use Laminas\Code\Generator\ParameterGenerator;
8
use Laminas\Code\Generator\PropertyGenerator;
9
use ProxyManager\Factory\RemoteObject\AdapterInterface;
10
use ProxyManager\Generator\MethodGenerator;
11
use ProxyManager\ProxyGenerator\Util\Properties;
12
use ProxyManager\ProxyGenerator\Util\UnsetPropertiesGenerator;
13
use ReflectionClass;
14
15
/**
16
 * The `staticProxyConstructor` implementation for remote object proxies
17
 */
18
class StaticProxyConstructor extends MethodGenerator
19
{
20
    /**
21
     * Constructor
22
     *
23
     * @param ReflectionClass   $originalClass Reflection of the class to proxy
24
     * @param PropertyGenerator $adapter       Adapter property
25
     */
26
    public function __construct(ReflectionClass $originalClass, PropertyGenerator $adapter)
27 1
    {
28
        $adapterName = $adapter->getName();
29 1
30
        parent::__construct(
31 1
            'staticProxyConstructor',
32 1
            [new ParameterGenerator($adapterName, AdapterInterface::class)],
33 1
            MethodGenerator::FLAG_PUBLIC | MethodGenerator::FLAG_STATIC,
34 1
            null,
35 1
            'Constructor for remote object control\n\n'
36
            . '@param \\ProxyManager\\Factory\\RemoteObject\\AdapterInterface \$adapter'
37 1
        );
38
39
        $body = 'static $reflection;' . "\n\n"
40
            . '$reflection = $reflection ?? new \ReflectionClass(__CLASS__);' . "\n"
41
            . '$instance   = $reflection->newInstanceWithoutConstructor();' . "\n\n"
42
            . '$instance->' . $adapterName . ' = $' . $adapterName . ";\n\n"
43 1
            . UnsetPropertiesGenerator::generateSnippet(Properties::fromReflectionClass($originalClass), 'instance');
44 1
45
        $this->setBody($body . "\n\nreturn \$instance;");
46 1
    }
47
}
48