From 60cd40b97584f01476afdaa6b10c43f486f732f8 Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Thu, 28 Jun 2018 20:45:20 +0200 Subject: [PATCH] Remove not needed count() and "return true" from hook handlers This patch fixes two styls issues I could not separate: * Hook handler functions do not need to return true. This is the default anyway, and meaningless. * Counting is possibly expensive and not needed when all we need to know is if an array is empty or not. Change-Id: I460776c981638806a606d9bf88fc8579d6da8c0e --- includes/ApiQueryExtracts.php | 2 +- includes/Hooks.php | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/includes/ApiQueryExtracts.php b/includes/ApiQueryExtracts.php index 5d7c81f..1c5aa27 100644 --- a/includes/ApiQueryExtracts.php +++ b/includes/ApiQueryExtracts.php @@ -81,7 +81,7 @@ class ApiQueryExtracts extends ApiQueryBase { */ public function execute() { $titles = $this->getPageSet()->getGoodTitles(); - if ( count( $titles ) == 0 ) { + if ( $titles === [] ) { return; } $isXml = $this->getMain()->isInternalMode() diff --git a/includes/Hooks.php b/includes/Hooks.php index 9b394e4..eb08f7e 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -13,13 +13,13 @@ class Hooks { /** * ApiOpenSearchSuggest hook handler * @param array &$results Array of search results - * @return bool */ public static function onApiOpenSearchSuggest( &$results ) { $config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'textextracts' ); - if ( !$config->get( 'ExtractsExtendOpenSearchXml' ) || !count( $results ) ) { - return true; + if ( !$config->get( 'ExtractsExtendOpenSearchXml' ) || $results === [] ) { + return; } + foreach ( array_chunk( array_keys( $results ), ApiBase::LIMIT_SML1 ) as $pageIds ) { $api = new ApiMain( new FauxRequest( [ @@ -43,6 +43,5 @@ class Hooks { } } } - return true; } }