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

PhpConstant   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 3 1
A toString() 0 5 1
A getName() 0 3 1
A __construct() 0 4 1
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
}