NullObjectMethodInterceptor::generateMethod()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 5
cts 5
cp 1
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManager\ProxyGenerator\NullObject\MethodGenerator;
6
7
use Laminas\Code\Reflection\MethodReflection;
8
use ProxyManager\Generator\MethodGenerator;
9
use ProxyManager\Generator\Util\IdentifierSuffixer;
10
11
/**
12
 * Method decorator for null objects
13
 */
14
class NullObjectMethodInterceptor extends MethodGenerator
15
{
16
    /**
17
     * @return static
18
     */
19
    public static function generateMethod(MethodReflection $originalMethod) : self
20
    {
21 3
        /** @var static $method */
22
        $method = static::fromReflectionWithoutBodyAndDocBlock($originalMethod);
23
24 3
        if ($originalMethod->returnsReference()) {
25
            $reference = IdentifierSuffixer::getIdentifier('ref');
26 3
27 1
            $method->setBody("\$reference = null;\nreturn \$" . $reference . ';');
28
        }
29 1
30
        return $method;
31
    }
32
}
33