ProxiedMethodReturnExpression   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 16 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManager\Generator\Util;
6
7
use ReflectionMethod;
8
9
/**
10
 * Utility class to generate return expressions in method, given a method signature.
11
 *
12
 * This is required since return expressions may be forbidden by the method signature (void).
13
 */
14
final class ProxiedMethodReturnExpression
15 6
{
16
    public static function generate(string $returnedValueExpression, ?ReflectionMethod $originalMethod) : string
17 6
    {
18 2
        $originalReturnType = $originalMethod === null
19
            ? null
20
            : $originalMethod->getReturnType();
21 4
22
        $originalReturnTypeName = $originalReturnType === null
23
            ? null
24
            : $originalReturnType->getName();
25
26
        if ($originalReturnTypeName === 'void') {
27
            return $returnedValueExpression . ";\nreturn;";
28
        }
29
30
        return 'return ' . $returnedValueExpression . ';';
31
    }
32
}
33