Completed
Pull Request — master (#37)
by Angelo
03:16 queued 01:16
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
use Moka\Proxy\ProxyInterface;
7
8
class ProxyClassGenerator
9
{
10
    const UNSAFE_METHODS = ['__call', '__construct', '__destruct', '__clone'];
11
12
    private static $template = '
13
    return new class extends %s implements %s
14
    {
15
        use %s;
16
        %s
17
    };
18
    ';
19
20 8
    public static function generateCode(string $classWillBeEtended): string
21
    {
22 8
        $reflection = new \ReflectionClass($classWillBeEtended);
23 8
        $methods = $reflection->getMethods();
24 8
        $methodsArray = [];
25 8
        foreach ($methods as $method) {
26 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...
27 8
                $methodsArray[] = ProxyMethodGenerator::generateMethodString($method);
28
            }
29
        }
30
31 8
        return sprintf(
32 8
            self::$template,
33 8
            $classWillBeEtended,
34 8
            ProxyInterface::class,
35 8
            ProxyTrait::class,
36 8
            implode(PHP_EOL, $methodsArray)
37
        );
38
    }
39
}
40