PhpConstant::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 1
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
    /** @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
}