PhpConstant   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getPhpName() 0 7 2
A getScalarValue() 0 3 1
A getChildrenTypes() 0 3 1
A __construct() 0 5 1
A endsWithSemicolon() 0 3 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
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->setValue($value);
18 58
        $this->setClass($class);
19 54
    }
20
21 54
    public function getPhpName(): string
22
    {
23 48
        if ($this->getClass() instanceof PhpClass) {
24
            return strtoupper(parent::getPhpName());
25 48
        }
26 30
27
        return parent::getPhpName();
28
    }
29 18
30
    public function setClass(?PhpClass $class): self
31
    {
32 54
        $this->class = $class;
33
34 54
        return $this;
35
    }
36 54
37
    public function getClass(): ?PhpClass
38
    {
39 48
        return $this->class;
40
    }
41 48
42
    public function getAssignmentDeclarator(): string
43
    {
44 48
        if ($this->getClass() instanceof PhpClass) {
45
            return 'const ';
46 48
        }
47 30
48
        return 'define(\'';
49
    }
50 18
51
    public function getAssignmentSign(): string
52
    {
53 48
        if ($this->getClass() instanceof PhpClass) {
54
            return ' = ';
55 48
        }
56 30
57
        return '\', ';
58
    }
59 18
60
    public function getAssignmentFinishing(): string
61
    {
62 48
        if ($this->getClass() instanceof PhpClass) {
63
            return '';
64 48
        }
65 30
66
        return ')';
67
    }
68 18
69
    public function getAcceptNonScalarValue(): bool
70
    {
71 58
        return false;
72
    }
73 58
74
    public function endsWithSemicolon(): bool
75
    {
76 48
        return true;
77
    }
78 48
79
    public function getChildrenTypes(): array
80
    {
81 2
        return [];
82
    }
83 2
84
    /**
85
     * Always return null to avoid having a literal string instead of quoted string.
86
     *
87
     * @param mixed $value
88
     */
89 38
    protected function getScalarValue($value)
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

89
    protected function getScalarValue(/** @scrutinizer ignore-unused */ $value)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
90
    {
91 38
        return null;
92
    }
93
}
94