PhpConstant   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 41
ccs 11
cts 11
cp 1
rs 10
c 2
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
    /** @var float|int|string  */
15
    private $value;
16
17
    /**
18
     * PhpConstant constructor.
19
     * @param string $name
20
     * @param float|int|string $value
21 5
     */
22
    public function __construct($name, $value)
23 5
    {
24 5
        $this->name = $name;
25 5
        $this->value = $value;
26
    }
27
28
    /**
29
     * @return mixed
30 4
     */
31
    public function getValue()
32 4
    {
33
        return $this->value;
34
    }
35
36
    /**
37
     * @return mixed
38 5
     */
39
    public function getName()
40 5
    {
41
        return $this->name;
42
    }
43 5
44
    protected function toString()
45 5
    {
46
        $val = var_export($this->value, true);
47 5
        return <<<PHP
48
{$this->renderDescriptionAsPhpDoc()}{$this->renderVisibility()}const {$this->name} = $val;
49
50
51
PHP;
52
53
    }
54
55
56
}