From f83ee87902b32cf6a928490d2c30ae667e2de6ca Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Fri, 15 Feb 2019 23:34:58 +0000 Subject: [PATCH] Make this pattern a bit more reusable --- src/Parsedown.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/Parsedown.php b/src/Parsedown.php index 5bc31c6..6724bb6 100644 --- a/src/Parsedown.php +++ b/src/Parsedown.php @@ -60,13 +60,23 @@ final class Parsedown { list($Blocks, $State) = self::blocks($Lines, $State); - $StateRenderables = \array_map( - /** @return StateRenderable */ - function (Block $Block) { return $Block->stateRenderable(); }, - $Blocks - ); + return [self::stateRenderablesFrom($Blocks), $State]; + } - return [$StateRenderables, $State]; + /** + * @param Component[] $Components + * @return StateRenderable[] + */ + public static function stateRenderablesFrom($Components) + { + return \array_map( + /** + * @param Component $Component + * @return StateRenderable + */ + function ($Component) { return $Component->stateRenderable(); }, + $Components + ); } /** @@ -160,11 +170,7 @@ final class Parsedown */ public static function line($text, State $State) { - return \array_map( - /** @return StateRenderable */ - function (Inline $Inline) { return $Inline->stateRenderable(); }, - self::inlines($text, $State) - ); + return self::stateRenderablesFrom(self::inlines($text, $State)); } /**