PropertyGenerator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 46
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A code() 0 17 3
1
<?php declare(strict_types = 1);
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>.
4
 * on 03.09.16 at 11:30
5
 */
6
namespace samsonphp\generator;
7
8
/**
9
 * Class property generation class.
10
 *
11
 * @author Vitaly Egorov <[email protected]>
12
 */
13
class PropertyGenerator extends AbstractGenerator
14
{
15
    use VisibilityTrait;
16
17
    /** @var string Property name */
18
    protected $name;
19
20
    /** @var string Property value */
21
    protected $value;
22
23
    /**
24
     * PropertyGenerator constructor.
25
     *
26
     * @param string                 $name   Property name
27
     * @param mixed                  $value  Property value
28
     * @param AbstractGenerator|null $parent Parent generator
29
     */
30
    public function __construct(string $name, $value = null, AbstractGenerator $parent = null)
31
    {
32
        $this->name = $name;
33
        $this->value = $value;
34
35
        parent::__construct($parent);
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function code(int $indentation = 0) : string
42
    {
43
        $code = $this->indentation($indentation)
44
            . $this->visibility
45
            . ' '
46
            . ($this->isStatic ? 'static ' : '')
47
            . '$'
48
            . $this->name
49
            . ';';
50
51
        // Add comments
52
        if (array_key_exists(CommentsGenerator::class, $this->generatedCode)) {
53
            $code = $this->generatedCode[CommentsGenerator::class] . "\n" . $code;
54
        }
55
56
        return $code;
57
    }
58
}
59