PropertyTemplate   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 4 1
A doGenerate() 0 15 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Moka\Generator\Template;
5
6
use Moka\Exception\InvalidArgumentException;
7
8
/**
9
 * Class PropertyTemplate
10
 * @package Moka\Generator\Template
11
 */
12
class PropertyTemplate implements TemplateInterface
13
{
14
    use VisibilityTrait;
15
16
    private const TEMPLATE = '
17
        %s %s $%s;
18
    ';
19
20
    /**
21
     * @param \Reflector|\ReflectionProperty $property
22
     * @return string
23
     * @throws \RuntimeException
24
     * @throws InvalidArgumentException
25
     */
26 5
    public static function generate(\Reflector $property): string
27
    {
28 5
        return static::doGenerate($property);
29
    }
30
31
    /**
32
     * @param \ReflectionProperty $property
33
     * @return string
34
     * @throws \RuntimeException
35
     * @throws InvalidArgumentException
36
     */
37 5
    protected static function doGenerate(\ReflectionProperty $property): string
38
    {
39 5
        $visibility = static::getVisibility($property);
40
41 5
        $static = $property->isStatic() ? 'static' : '';
42
43 5
        $name = $property->name;
44
45 5
        return sprintf(
46 5
            self::TEMPLATE,
47
            $visibility,
48
            $static,
49
            $name
50
        );
51
    }
52
}
53