| Total Complexity | 15 |
| Total Lines | 85 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 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 |
|
| 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 |