Skip to content

Commit

Permalink
SDK-5412: Fix the error with integration of the constant array (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmytroKlymanSpryker authored Nov 9, 2023
1 parent 8da0b57 commit 0588c85
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions src/Builder/ClassModifier/ClassConstant/ClassConstantModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
*
Expand All @@ -104,4 +121,22 @@ protected function parseSingleValue(string $value): Expr

return $tree[0]->expr;
}

/**
* @param array<mixed> $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;
}
}

0 comments on commit 0588c85

Please sign in to comment.