From 56e566f35182fe4ed3b98f7747a770c4af6d55ed Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 30 Jan 2018 15:59:35 -0800 Subject: [PATCH] Improve and simplify typehint and type docs in VectorTemplate * renderPortals() - Takes array only, enforce this with a type hint. * renderPortal() - Actually takes either array or string as $content, fix the type doc to match the code. * renderNavigation() - Simplify by removing support for non-array $elements, fixing one caller. This and other minor changes are tracked under T140664, which intends to reduce code complexity in Vector to (potentially) make it portable to an HTML template. Change-Id: Idc95d023a55c83450b041109745cfbcbcd04f580 --- VectorTemplate.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/VectorTemplate.php b/VectorTemplate.php index 2687ddc..96e36ee 100644 --- a/VectorTemplate.php +++ b/VectorTemplate.php @@ -152,7 +152,7 @@ class VectorTemplate extends BaseTemplate {

msg( 'navigation-heading' ) ?>

- renderNavigation( 'PERSONAL' ); ?> + renderNavigation( [ 'PERSONAL' ] ); ?>
renderNavigation( [ 'NAMESPACES', 'VARIANTS' ] ); ?>
@@ -221,7 +221,7 @@ class VectorTemplate extends BaseTemplate { * * @param array $portals */ - protected function renderPortals( $portals ) { + protected function renderPortals( array $portals ) { // Force the rendering of the following portals if ( !isset( $portals['SEARCH'] ) ) { $portals['SEARCH'] = true; @@ -262,7 +262,7 @@ class VectorTemplate extends BaseTemplate { /** * @param string $name - * @param array $content + * @param array|string $content * @param null|string $msg * @param null|string|array $hook */ @@ -316,12 +316,7 @@ class VectorTemplate extends BaseTemplate { * * @param array $elements */ - protected function renderNavigation( $elements ) { - // If only one element was given, wrap it in an array, allowing more - // flexible arguments - if ( !is_array( $elements ) ) { - $elements = [ $elements ]; - } + protected function renderNavigation( array $elements ) { // Render elements foreach ( $elements as $name => $element ) { switch ( $element ) {