Completed
Push — master ( 7ee214...32fd8d )
by Alberto
19s
created

PropertyTemplate   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 37
ccs 11
cts 11
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
/**
7
 * Class PropertyTemplate
8
 * @package Moka\Generator\Template
9
 */
10
class PropertyTemplate implements TemplateInterface
11
{
12
    use VisibilityTrait;
13
14
    const TEMPLATE = '
15
        %s %s $%s;
16
    ';
17
18
    /**
19
     * @param \ReflectionProperty $property
20
     * @return string
21
     */
22 4
    public static function generate(\Reflector $property): string
23
    {
24 4
        return static::doGenerate($property);
1 ignored issue
show
Compatibility introduced by
$property of type object<Reflector> is not a sub-type of object<ReflectionProperty>. It seems like you assume a concrete implementation of the interface Reflector to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
25
    }
26
27
    /**
28
     * @param \ReflectionProperty $property
29
     * @return string
30
     */
31 4
    protected static function doGenerate(\ReflectionProperty $property): string
32
    {
33 4
        $visibility = static::getVisibility($property);
34
35 4
        $static = $property->isStatic() ? 'static' : '';
36
37 4
        $name = $property->name;
38
39 4
        return sprintf(
40 4
            self::TEMPLATE,
41 4
            $visibility,
42 4
            $static,
43 4
            $name
44
        );
45
    }
46
}
47