PropertyTemplate::doGenerate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 15
ccs 6
cts 6
cp 1
crap 2
rs 9.7666
c 0
b 0
f 0
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