| 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->setValue($value); |
||
| 18 | 58 | $this->setClass($class); |
|
| 19 | 54 | } |
|
| 20 | |||
| 21 | 54 | public function getPhpName(): string |
|
| 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) |
|
| 92 | } |
||
| 93 | } |
||
| 94 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.