Commit fc306ce6 authored by Guillaume Perréal's avatar Guillaume Perréal

Simplifie le cast en string des unions.

parent 4e22354b
......@@ -58,14 +58,17 @@ final class Union extends AbstractType
*/
public function castToStringOrStringArray(string $expr): string
{
$cast = $expr;
foreach ($this->types as $type) {
$alternatives = $this->types;
$first = array_shift($alternatives);
$cast = $first->castToStringOrStringArray($expr);
foreach ($alternatives as $type) {
$typeCast = $type->castToStringOrStringArray($expr);
if ($typeCast === $cast) {
continue;
}
$check = $type->checkType($expr);
if ($check) {
$typeCast = $type->castToStringOrStringArray($expr);
if ($typeCast !== $cast) {
$cast = sprintf('(%s ? %s : %s)', $check, $type->castToStringOrStringArray($expr), $cast);
}
$cast = sprintf('(%s ? %s : %s)', $check, $typeCast, $cast);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment