From 0588c85532bc96200fe4bd19f7117a785fea8e5d Mon Sep 17 00:00:00 2001 From: Dmytro Klyman Date: Thu, 9 Nov 2023 13:45:56 +0100 Subject: [PATCH] SDK-5412: Fix the error with integration of the constant array (#153) --- .../ClassConstant/ClassConstantModifier.php | 41 +++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/src/Builder/ClassModifier/ClassConstant/ClassConstantModifier.php b/src/Builder/ClassModifier/ClassConstant/ClassConstantModifier.php index 1ed7f73e..4ca6ad1a 100644 --- a/src/Builder/ClassModifier/ClassConstant/ClassConstantModifier.php +++ b/src/Builder/ClassModifier/ClassConstant/ClassConstantModifier.php @@ -71,9 +71,7 @@ public function setConstant( } } - if ($isLiteral) { - $value = $this->parseSingleValue((string)$value); - } + $value = $this->parseValue($value, $isLiteral); $visitors = [ new AddConstantVisitor($constantName, $value, $modifier), @@ -82,6 +80,25 @@ public function setConstant( return $this->addVisitorsClassInformationTransfer($classInformationTransfer, $visitors); } + /** + * @param mixed $value + * @param bool $isLiteral + * + * @return mixed + */ + protected function parseValue($value, bool $isLiteral) + { + if ($isLiteral) { + return $this->parseSingleValue((string)$value); + } + + if (is_array($value)) { + return $this->parseArrayValue($value); + } + + return $value; + } + /** * @param string $value * @@ -104,4 +121,22 @@ protected function parseSingleValue(string $value): Expr return $tree[0]->expr; } + + /** + * @param array $value + * + * @return array + */ + protected function parseArrayValue(array $value): array + { + foreach ($value as $idx => $val) { + if (!is_string($val) || strpos($val, '::') === false) { + continue; + } + + $value[$idx] = $this->parseSingleValue($val); + } + + return $value; + } }