Completed
Pull Request — master (#10)
by Viacheslav
07:30
created

PhpClassProperty   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 58.33%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 70
ccs 14
cts 24
cp 0.5833
rs 10
c 0
b 0
f 0
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setDefault() 0 4 1
A clearDefault() 0 4 1
A __construct() 0 4 1
A toString() 0 4 1
A setNamedVar() 0 4 1
A setDescription() 0 4 1
A getNamedVar() 0 3 1
A renderPhpDoc() 0 7 2
1
<?php
2
3
namespace Swaggest\PhpCodeBuilder;
4
5
6
use Swaggest\PhpCodeBuilder\Traits\Description;
7
use Swaggest\PhpCodeBuilder\Traits\StaticFlag;
8
use Swaggest\PhpCodeBuilder\Traits\Visibility;
9
10
class PhpClassProperty extends PhpTemplate
11
{
12
    use Visibility;
13
    use StaticFlag;
14
15
    /** @var PhpNamedVar */
16
    private $namedVar;
17
18 11
    public function __construct($name, PhpAnyType $type = null, $visibility = PhpFlags::VIS_PUBLIC)
19
    {
20 11
        $this->namedVar = new PhpNamedVar($name, $type);
21 11
        $this->visibility = $visibility;
22 11
    }
23
24
    /**
25
     * @param mixed $value
26
     * @return $this
27
     */
28
    public function setDefault($value)
29
    {
30
        $this->namedVar->setDefault($value);
31
        return $this;
32
    }
33
34
    /**
35
     * @return $this
36
     */
37
    public function clearDefault()
38
    {
39
        $this->namedVar->clearDefault();
40
        return $this;
41
    }
42
43
    /**
44
     * @return PhpNamedVar
45
     */
46 5
    public function getNamedVar()
47
    {
48 5
        return $this->namedVar;
49
    }
50
51
    /**
52
     * @param PhpNamedVar $namedVar
53
     * @return PhpClassProperty
54
     */
55
    public function setNamedVar($namedVar)
56
    {
57
        $this->namedVar = $namedVar;
58
        return $this;
59
    }
60
61 3
    public function setDescription($description)
62
    {
63 3
        $this->namedVar->setDescription($description);
64 3
        return $this;
65
    }
66
67 11
    private function renderPhpDoc()
68
    {
69 11
        if ($tagValue = $this->namedVar->renderPhpDocValue()) {
70 11
            return (new PhpDocTag(PhpDoc::TAG_VAR, $tagValue)) . "\n";
71
        }
72
73
        return '';
74
    }
75
76 11
    protected function toString()
77
    {
78
        return <<<PHP
79 11
{$this->renderPhpDoc()}{$this->renderVisibility()}{$this->renderIsStatic()}\${$this->namedVar->getName()}{$this->namedVar->renderDefault()};
80
81
82
PHP;
83
84
    }
85
}