ReturnTypeTemplate   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 4 1
A doGenerate() 0 17 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Moka\Generator\Template;
5
6
/**
7
 * Class ReturnTypeTemplate
8
 * @package Moka\Generator\Template
9
 */
10
class ReturnTypeTemplate implements TemplateInterface
11
{
12
    private const TEMPLATE = ': %s%s';
13
14
    /**
15
     * @param \Reflector|\ReflectionMethod $method
16
     * @return string
17
     */
18 7
    public static function generate(\Reflector $method): string
19
    {
20 7
        return static::doGenerate($method);
21
    }
22
23
    /**
24
     * @param \ReflectionMethod $method
25
     * @return string
26
     */
27 7
    protected static function doGenerate(\ReflectionMethod $method): string
28
    {
29 7
        $originalReturnType = $method->getReturnType();
30 7
        $allowsNull = $originalReturnType->allowsNull()
31 1
            ? '?'
32 7
            : '';
33
34 7
        $returnType = 'self' === $originalReturnType->getName()
35 1
            ? $method->getDeclaringClass()->name
36 7
            : $originalReturnType->getName();
37
38 7
        return sprintf(
39 7
            self::TEMPLATE,
40
            $allowsNull,
41
            $returnType
42
        );
43
    }
44
}
45