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

ProxyMethodGenerator   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 95.65%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 48
ccs 22
cts 23
cp 0.9565
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
C generateMethodString() 0 32 7
A getType() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Moka\Generator;
5
6
7
class ProxyMethodGenerator
8
{
9
    private static $template = '
10
        public %s function %s(%s)%s
11
        {
12
            %s$this->__call("%s", func_get_args());
13
        }
14
    ';
15
16 8
    public static function generateMethodString(\ReflectionMethod $method)
17
    {
18 8
        $static = $method->isStatic() ? 'static' : '';
19 8
        $originalReturnType = $method->getReturnType();
20
21 8
        $returnType = !$originalReturnType ? '' : ProxyReturnGenerator::generateMethodReturnType($originalReturnType, $method);
22
23 8
        $parameters = $method->getParameters();
24 8
        $arguments = [];
25 8
        if ($parameters) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $parameters of type ReflectionParameter[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
26 8
            foreach ($method->getParameters() as $parameter) {
27 8
                $arguments[] = ProxyArgumentGenerator::generateMethodParameter($parameter);
28
            }
29
        }
30
31 8
        $method->getReturnType();
32
33 8
        $returnStatement = 'return ';
34 8
        if (null !== $originalReturnType && self::getType($originalReturnType) === 'void') {
35
            $returnStatement = '';
36
        }
37
38 8
        return sprintf(
39 8
            self::$template,
40 8
            $static,
41 8
            $method->getName(),
0 ignored issues
show
Bug introduced by
Consider using $method->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
42 8
            implode(', ', $arguments),
43 8
            $returnType,
44 8
            $returnStatement,
45 8
            $method->getName()
0 ignored issues
show
Bug introduced by
Consider using $method->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
46
        );
47
    }
48
49 2
    protected static function getType(\ReflectionType $type)
50
    {
51 2
        return (string)$type;
52
    }
53
54
}
55