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

PhpConstant::hasAccessibilityConstraint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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