Completed
Pull Request — master (#1)
by Viacheslav
02:50
created

PhpConstant::toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Swaggest\PhpCodeBuilder;
4
5
use Swaggest\PhpCodeBuilder\Traits\Description;
6
use Swaggest\PhpCodeBuilder\Traits\Visibility;
7
8
class PhpConstant extends PhpTemplate
9
{
10
    use Visibility;
11
    use Description;
12
13
    protected $name;
14
    private $value;
15
16
    /**
17
     * PhpConstant constructor.
18
     * @param string $name
19
     * @param string $value
20
     */
21 2
    public function __construct($name, $value)
22
    {
23 2
        $this->name = $name;
24 2
        $this->value = $value;
25 2
    }
26
27
    /**
28
     * @return mixed
29
     */
30 1
    public function getValue()
31
    {
32 1
        return $this->value;
33
    }
34
35
    /**
36
     * @return mixed
37
     */
38 2
    public function getName()
39
    {
40 2
        return $this->name;
41
    }
42
43 2
    protected function toString()
44
    {
45 2
        $val = var_export($this->value, true);
46
        return <<<PHP
47 2
{$this->renderDescriptionAsPhpDoc()}{$this->renderVisibility()}const {$this->name} = $val;
48
49
50
PHP;
51
52
    }
53
54
55
}