Completed
Push — master ( 60b0b0...6547f6 )
by Vitaly
03:07
created

PropertyGenerator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A defStatic() 0 6 1
A code() 0 12 2
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
    /** @var string Property name */
16
    protected $name;
17
18
    /** @var bool Flag that method is static */
19
    protected $isStatic = false;
20
21
    /** @var string Method visibility */
22
    protected $visibility = ClassGenerator::VISIBILITY_PUBLIC;
23
24
    /**
25
     * PropertyGenerator constructor.
26
     *
27
     * @param string                 $name Property name
28
     * @param AbstractGenerator|null $parent Parent generator
29
     */
30
    public function __construct(string $name, AbstractGenerator $parent = null)
31
    {
32
        $this->name = $name;
33
34
        parent::__construct($parent);
35
    }
36
37
    /**
38
     * Set method to be static.
39
     *
40
     * @return PropertyGenerator
41
     */
42
    public function defStatic() : PropertyGenerator
43
    {
44
        $this->isStatic = true;
45
46
        return $this;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function code($indentation = 0) : string
53
    {
54
        $this->generatedCode .= $this->indentation($indentation)
55
            .$this->visibility
56
            .' '
57
            .($this->isStatic ? 'static ' : '')
58
            .'$'
59
            .$this->name
60
            .';';
61
62
        return $this->generatedCode;
63
    }
64
}
65