Skip to content

Commit 0588c85

Browse files
SDK-5412: Fix the error with integration of the constant array (#153)
1 parent 8da0b57 commit 0588c85

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

src/Builder/ClassModifier/ClassConstant/ClassConstantModifier.php

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ public function setConstant(
7171
}
7272
}
7373

74-
if ($isLiteral) {
75-
$value = $this->parseSingleValue((string)$value);
76-
}
74+
$value = $this->parseValue($value, $isLiteral);
7775

7876
$visitors = [
7977
new AddConstantVisitor($constantName, $value, $modifier),
@@ -82,6 +80,25 @@ public function setConstant(
8280
return $this->addVisitorsClassInformationTransfer($classInformationTransfer, $visitors);
8381
}
8482

83+
/**
84+
* @param mixed $value
85+
* @param bool $isLiteral
86+
*
87+
* @return mixed
88+
*/
89+
protected function parseValue($value, bool $isLiteral)
90+
{
91+
if ($isLiteral) {
92+
return $this->parseSingleValue((string)$value);
93+
}
94+
95+
if (is_array($value)) {
96+
return $this->parseArrayValue($value);
97+
}
98+
99+
return $value;
100+
}
101+
85102
/**
86103
* @param string $value
87104
*
@@ -104,4 +121,22 @@ protected function parseSingleValue(string $value): Expr
104121

105122
return $tree[0]->expr;
106123
}
124+
125+
/**
126+
* @param array<mixed> $value
127+
*
128+
* @return array
129+
*/
130+
protected function parseArrayValue(array $value): array
131+
{
132+
foreach ($value as $idx => $val) {
133+
if (!is_string($val) || strpos($val, '::') === false) {
134+
continue;
135+
}
136+
137+
$value[$idx] = $this->parseSingleValue($val);
138+
}
139+
140+
return $value;
141+
}
107142
}

0 commit comments

Comments
 (0)