Skip to content

Commit

Permalink
Cleanup map call
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Apr 25, 2019
1 parent 83a17d1 commit 9cbedb1
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/SafeHtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ public function getContent()
}

/**
* @param ...$toAppend
* @param $html
*
* @return $this
* @throws \Exception
*/
public function append(...$toAppend)
public function append(...$html)
{
foreach($toAppend as $html)
foreach($html as $toAppend)
{
$this->content .= self::escape($html);
$this->content .= self::escape($toAppend);
}
return $this;
}
Expand All @@ -51,19 +51,14 @@ public static function escape($input, $arrayGlue = ' ')
return $input;
}

if(is_array($input))
if($input instanceof ISafeHtmlProducer)
{
return new static(
implode(
$arrayGlue,
array_map(function ($input) use ($arrayGlue) { return SafeHtml::escape($input, $arrayGlue); }, $input)
)
);
return $input->produceSafeHTML();
}

if($input instanceof ISafeHtmlProducer)
if(is_array($input))
{
return $input->produceSafeHTML();
return new static(implode($arrayGlue, array_map([SafeHtml::class, 'escape'], $input, [$arrayGlue])));
}

try
Expand All @@ -73,9 +68,8 @@ public static function escape($input, $arrayGlue = ' ')
}
catch(\Exception $ex)
{
$class = get_class($input);
throw new \Exception(
"Object (of class '{$class}') implements " .
"Object (of class '" . get_class($input) . "') implements " .
"ISafeHTMLProducer but did not return anything " .
"renderable from produceSafeHTML()."
);
Expand Down

0 comments on commit 9cbedb1

Please sign in to comment.