From 1839baef36192011fca9f0ede43d86559b29739b Mon Sep 17 00:00:00 2001 From: ebremner <ebremner@uwaterloo.ca> Date: Tue, 1 Dec 2020 13:33:32 -0500 Subject: [PATCH] ISTWCMS-4199: coding standards --- src/Service/UWService.php | 17 +++++++++++------ src/Service/UWServiceInterface.php | 16 +++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/Service/UWService.php b/src/Service/UWService.php index 76daf1da..21d6d0a5 100644 --- a/src/Service/UWService.php +++ b/src/Service/UWService.php @@ -32,7 +32,7 @@ class UWService implements UWServiceInterface { private $database; /** - * Simplify_menu menu. + * Simplify_menu menu items. * * @var \Drupal\simplify_menu\MenuItems */ @@ -45,6 +45,8 @@ class UWService implements UWServiceInterface { * Entity Type Manager from core. * @param \Drupal\Core\Database\Connection $database * The database entity. + * @param \Drupal\simplify_menu\MenuItems $simplifyMenu + * The simplify_menu menu items. */ public function __construct(EntityTypeManagerInterface $entityTypeManager, Connection $database, MenuItems $simplifyMenu) { $this->entityTypeManager = $entityTypeManager; @@ -271,7 +273,7 @@ class UWService implements UWServiceInterface { /** * {@inheritDoc} */ - public function uwGetMenu(string $menu_name = 'main', $include_parent_in_count = FALSE): array { + public function uwGetMenu(string $menu_name = 'main', bool $count_menu_items = FALSE, bool $include_parent_in_count = FALSE): array { // Get the main menu from the simplify menu module. $menu = $this->simplifyMenu->getMenuTree($menu_name); @@ -279,10 +281,12 @@ class UWService implements UWServiceInterface { // Set it to the menu_tree which is done by simplify menu. $menu = $menu['menu_tree']; - $menu_items_count = 0; + // If we want to have the count of menu items, then count them. + if ($count_menu_items) { - // Add the count of the menu items. - $menu = $this->uwSetMenuItems($menu, $include_parent_in_count); + // Add the count of the menu items. + $menu = $this->uwSetMenuItems($menu, $include_parent_in_count); + } return $menu; } @@ -290,7 +294,7 @@ class UWService implements UWServiceInterface { /** * {@inheritDoc} */ - public function uwSetMenuItems($menus, $include_parent_in_count = FALSE): array { + public function uwSetMenuItems(array $menus, bool $include_parent_in_count = FALSE): array { // Step through the menu and do a few things: // (a) Remove the Home link (this will be a house icon) @@ -370,4 +374,5 @@ class UWService implements UWServiceInterface { } } } + } diff --git a/src/Service/UWServiceInterface.php b/src/Service/UWServiceInterface.php index e31f9ed1..ba589055 100644 --- a/src/Service/UWServiceInterface.php +++ b/src/Service/UWServiceInterface.php @@ -88,13 +88,15 @@ interface UWServiceInterface { * * @param string $menu_name * A string to the machine name of the menu to get. - * @param $include_parent_in_count + * @param bool $count_menu_items + * A boolean on whether to count the number of menu items. + * @param bool $include_parent_in_count * A boolean on whether to include the parent in the menu items count. * * @return array * An array of the menu. */ - public function uwGetMenu(string $menu_name = 'main', $include_parent_in_count = false): array; + public function uwGetMenu(string $menu_name = 'main', bool $count_menu_items = FALSE, bool $include_parent_in_count = FALSE): array; /** * A function to setup the menu for UW display. @@ -125,22 +127,22 @@ interface UWServiceInterface { * So it should with the recursive function it will return 11. * If we include the parent the count will be 12. * - * @param &$menus + * @param array $menus * A reference to the array list of menu items. - * @param $include_parent_in_count + * @param bool $include_parent_in_count * A boolean on whether to include the parent in the menu items count. * * @return array * An array of the updated menu items. */ - public function uwSetMenuItems($menus, $include_parent_in_count = false): array; + public function uwSetMenuItems(array $menus, bool $include_parent_in_count = FALSE): array; /** * A function to recursively count the number of menu items in the submenu. * - * @param $menu + * @param array $menu * An array that contains the submenu. - * @param $menu_items_count + * @param int &$menu_items_count * A reference to the integer that is storing the number of menu items. */ public function uwCountMenuItems(array $menu, int &$menu_items_count): void; -- GitLab