Passed
Push — develop ( 6b3bb3...b964e0 )
by Mikaël
01:53 queued 11s
created

PhpConstant   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 85
ccs 34
cts 34
cp 1
rs 10
c 0
b 0
f 0
wmc 15

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getChildrenTypes() 0 3 1
A endsWithSemicolon() 0 3 1
A getPhpName() 0 7 2
A __construct() 0 6 1
A getAssignmentDeclarator() 0 7 2
A getAssignmentFinishing() 0 7 2
A getAcceptNonScalarValue() 0 3 1
A setClass() 0 5 1
A getClass() 0 3 1
A getAssignmentSign() 0 7 2
A getScalarValue() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WsdlToPhp\PhpGenerator\Element;
6
7
class PhpConstant extends AbstractElement implements AccessRestrictedElementInterface, AssignedValueElementInterface
8
{
9
    use AccessRestrictedElementTrait;
10
    use AssignedValueElementTrait;
11
12
    protected ?PhpClass $class;
13
14 58
    public function __construct(string $name, $value = null, ?PhpClass $class = null)
15
    {
16 58
        parent::__construct($name);
17
        $this
18 58
            ->setValue($value)
19 54
            ->setClass($class)
20
        ;
21 54
    }
22
23 48
    public function getPhpName(): string
24
    {
25 48
        if ($this->getClass() instanceof PhpClass) {
26 30
            return strtoupper(parent::getPhpName());
27
        }
28
29 18
        return parent::getPhpName();
30
    }
31
32 54
    public function setClass(?PhpClass $class): self
33
    {
34 54
        $this->class = $class;
35
36 54
        return $this;
37
    }
38
39 48
    public function getClass(): ?PhpClass
40
    {
41 48
        return $this->class;
42
    }
43
44 48
    public function getAssignmentDeclarator(): string
45
    {
46 48
        if ($this->getClass() instanceof PhpClass) {
47 30
            return 'const ';
48
        }
49
50 18
        return 'define(\'';
51
    }
52
53 48
    public function getAssignmentSign(): string
54
    {
55 48
        if ($this->getClass() instanceof PhpClass) {
56 30
            return ' = ';
57
        }
58
59 18
        return '\', ';
60
    }
61
62 48
    public function getAssignmentFinishing(): string
63
    {
64 48
        if ($this->getClass() instanceof PhpClass) {
65 30
            return '';
66
        }
67
68 18
        return ')';
69
    }
70
71 58
    public function getAcceptNonScalarValue(): bool
72
    {
73 58
        return false;
74
    }
75
76 48
    public function endsWithSemicolon(): bool
77
    {
78 48
        return true;
79
    }
80
81 2
    public function getChildrenTypes(): array
82
    {
83 2
        return [];
84
    }
85
86
    /**
87
     * Always return null to avoid having a literal string instead of quoted string.
88
     */
89 38
    protected function getScalarValue()
90
    {
91 38
        return null;
92
    }
93
}
94