From c1cd664a047a677e4593ece92705d6204fb9f352 Mon Sep 17 00:00:00 2001 From: kylekatarnls Date: Fri, 3 Mar 2023 20:23:10 +0100 Subject: [PATCH] Base enum label validity on constant name rule As per https://wiki.php.net/rfc/enumerations https://www.php.net/manual/en/language.constants.php --- .../PDepend/Source/Language/PHP/AbstractPHPParser.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/php/PDepend/Source/Language/PHP/AbstractPHPParser.php b/src/main/php/PDepend/Source/Language/PHP/AbstractPHPParser.php index 5d2514e21a..26747bf679 100644 --- a/src/main/php/PDepend/Source/Language/PHP/AbstractPHPParser.php +++ b/src/main/php/PDepend/Source/Language/PHP/AbstractPHPParser.php @@ -8173,17 +8173,12 @@ private function parseEnumCase() $this->tokenStack->add($this->tokenizer->next()); $this->tokenStack->push(); $this->consumeComments(); + $caseName = $this->tokenizer->currentToken()->image; - if (in_array($this->tokenizer->peek(), array( - Tokens::T_NEW, - Tokens::T_NULL, - Tokens::T_STRING, - Tokens::T_DEFAULT - ), true) === false) { + if (!preg_match('/^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/', $caseName)) { throw $this->getUnexpectedTokenException(); } - $caseName = $this->tokenizer->currentToken()->image; $this->tokenStack->add($this->tokenizer->next()); $this->consumeComments(); $case = $this->builder->buildEnumCase($caseName, $this->parseEnumCaseValue());