Completed
Push — master ( 6547f6...ac2ddd )
by Vitaly
02:13
created

PropertyGenerator::defPrivate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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 property visibility.
39
     *
40
     * @param string $visibility Property visibility
41
     *
42
     * @return PropertyGenerator
43
     */
44
    public function defVisibility(string $visibility) : PropertyGenerator
45
    {
46
        $this->visibility = $visibility;
47
48
        return $this;
49
    }
50
51
    /**
52
     * Set protected property visibility.
53
     *
54
     * @return PropertyGenerator
55
     */
56
    public function defProtected() : PropertyGenerator
57
    {
58
        return $this->defVisibility(ClassGenerator::VISIBILITY_PROTECTED);
59
    }
60
61
    /**
62
     * Set private property visibility.
63
     *
64
     * @return PropertyGenerator
65
     */
66
    public function defPrivate() : PropertyGenerator
67
    {
68
        return $this->defVisibility(ClassGenerator::VISIBILITY_PRIVATE);
69
    }
70
71
    /**
72
     * Set method to be static.
73
     *
74
     * @return PropertyGenerator
75
     */
76
    public function defStatic() : PropertyGenerator
77
    {
78
        $this->isStatic = true;
79
80
        return $this;
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function code($indentation = 0) : string
87
    {
88
        $this->generatedCode .= $this->indentation($indentation)
89
            .$this->visibility
90
            .' '
91
            .($this->isStatic ? 'static ' : '')
92
            .'$'
93
            .$this->name
94
            .';';
95
96
        return $this->generatedCode;
97
    }
98
}
99