VectorComponentUserLinks: Replace array_reduce with array_filter

Looks easier to understand:
array_reduce adds the count() of all inner arrays and returns an
integer, 0 when all is empty and the count when items in there.
array_filter removes the empty inner arrays and when the returned outer
array still has an inner array, it is non-empty.

Change-Id: Ib0acb9be8d4d64cfb7d7d124c5a3de500f6b0232
This commit is contained in:
Umherirrender 2024-01-12 01:25:40 +01:00
parent 32d9da47fb
commit 4d8c06cadb

View file

@ -320,13 +320,9 @@ class VectorComponentUserLinks implements VectorComponent {
] );
return [
'is-wide' => array_reduce(
[ $overflow, $notifications, $userPage, $userInterfacePreferences ],
static function ( $carry, $list ) {
return count( $list ) + $carry;
},
0
),
'is-wide' => array_filter(
[ $overflow, $notifications, $userPage, $userInterfacePreferences ]
) !== [],
'data-user-links-notifications' => $notificationsMenu->getTemplateData(),
'data-user-links-overflow' => $overflowMenu->getTemplateData(),
'data-user-links-preferences' => $preferencesMenu->getTemplateData(),