Completed
Pull Request — master (#37)
by Angelo
02:34
created

ProxyClassGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 32
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A generateCode() 0 19 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Moka\Generator;
5
6
7
use Moka\Proxy\ProxyInterface;
8
9
class ProxyClassGenerator
10
{
11
    const UNSAFE_METHODS = ['__call', '__construct', '__destruct', '__clone'];
12
13
    private static $template = '
14
    return new class extends %s implements %s
15
    {
16
        use %s;
17
        %s
18
    };
19
    ';
20
21 8
    public static function generateCode(string $classWillBeEtended): string
22
    {
23 8
        $reflection = new \ReflectionClass($classWillBeEtended);
24 8
        $methods = $reflection->getMethods();
25 8
        $methodsArray = [];
26 8
        foreach ($methods as $method) {
27 8
            if (!in_array($method->getName(), self::UNSAFE_METHODS, true)) {
0 ignored issues
show
Bug introduced by
Consider using $method->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
28 8
                $methodsArray[] = ProxyMethodGenerator::generateMethodString($method);
29
            }
30
        }
31
32 8
        return sprintf(
33 8
            self::$template,
34 8
            $classWillBeEtended,
35 8
            ProxyInterface::class,
36 8
            ProxyTrait::class,
37 8
            implode(PHP_EOL, $methodsArray)
38
        );
39
    }
40
}
41