PropertyInitializationTemplate   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 4 1
A doGenerate() 0 12 2
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