PropertyInitializationTemplate::doGenerate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 12
ccs 5
cts 5
cp 1
crap 2
rs 9.8666
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Moka\Generator\Template;
5
6
/**
7
 * Class PropertyInitializationTemplate
8
 * @package Moka\Generator\Template
9
 */
10
class PropertyInitializationTemplate implements TemplateInterface
11
{
12
    private const TEMPLATE = '
13
            unset(%s%s);
14
    ';
15
16
    /**
17
     * @param \Reflector|\ReflectionProperty $property
18
     * @return string
19
     */
20 5
    public static function generate(\Reflector $property): string
21
    {
22 5
        return self::doGenerate($property);
23
    }
24
25
    /**
26
     * @param \ReflectionProperty $property
27
     * @return string
28
     */
29 5
    protected static function doGenerate(\ReflectionProperty $property): string
30
    {
31 5
        $scope = $property->isStatic() ? 'self::$' : '$this->';
32
33 5
        $name = $property->name;
34
35 5
        return sprintf(
36 5
            self::TEMPLATE,
37
            $scope,
38
            $name
39
        );
40
    }
41
}
42