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
This commit is contained in:
Thiemo Kreuz 2018-06-28 20:45:20 +02:00
parent f607ff8d6c
commit 60cd40b975
2 changed files with 4 additions and 5 deletions

View file

@ -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()

View file

@ -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;
}
}