Remove all default "return true" from all hook handlers

This is the default for many years now. Returning true does nothing. It's
identical to returning nothing (null). The only meaningful value a hook
handler can return is false, and even this is meaningful only for very
few hooks.

TL;DR: A "return true" in a hook handler is always meaningless, dead code.

I'm interested in this because we (WMDE) might start working on this
extension soon and I want the code to be small and easy to maintain.

Change-Id: If4f32a55cdc38a3cc8af286d1cca7c0089bbfc43
This commit is contained in:
Thiemo Kreuz 2018-05-15 10:40:58 +02:00
parent 440d3678e8
commit 8a42f61697
2 changed files with 10 additions and 32 deletions

View file

@ -1136,18 +1136,17 @@ class Cite {
* want the counts to transcend pages and other instances
*
* @param Parser &$parser
*
* @return bool
*/
public function clearState( Parser &$parser ) {
if ( $parser->extCite !== $this ) {
return $parser->extCite->clearState( $parser );
$parser->extCite->clearState( $parser );
return;
}
# Don't clear state when we're in the middle of parsing
# a <ref> tag
if ( $this->mInCite || $this->mInReferences ) {
return true;
return;
}
$this->mGroupCnt = [];
@ -1156,20 +1155,17 @@ class Cite {
$this->mRefs = [];
$this->mReferencesErrors = [];
$this->mRefCallStack = [];
return true;
}
/**
* Gets run when the parser is cloned.
*
* @param Parser $parser
*
* @return bool
*/
public function cloneState( Parser $parser ) {
if ( $parser->extCite !== $this ) {
return $parser->extCite->cloneState( $parser );
$parser->extCite->cloneState( $parser );
return;
}
$parser->extCite = clone $this;
@ -1180,8 +1176,6 @@ class Cite {
$parser->extCite->mInCite = false;
$parser->extCite->mInReferences = false;
$parser->extCite->clearState( $parser );
return true;
}
/**
@ -1195,22 +1189,21 @@ class Cite {
* @param bool $afterParse True if called from the ParserAfterParse hook
* @param Parser &$parser
* @param string &$text
*
* @return bool
*/
public function checkRefsNoReferences( $afterParse, &$parser, &$text ) {
global $wgCiteResponsiveReferences;
if ( is_null( $parser->extCite ) ) {
return true;
return;
}
if ( $parser->extCite !== $this ) {
return $parser->extCite->checkRefsNoReferences( $afterParse, $parser, $text );
$parser->extCite->checkRefsNoReferences( $afterParse, $parser, $text );
return;
}
if ( $afterParse ) {
$this->mHaveAfterParse = true;
} elseif ( $this->mHaveAfterParse ) {
return true;
return;
}
if ( !$parser->getOptions()->getIsPreview() ) {
@ -1251,7 +1244,6 @@ class Cite {
} else {
$text .= $s;
}
return true;
}
/**
@ -1307,8 +1299,6 @@ class Cite {
* Initialize the parser hooks
*
* @param Parser $parser
*
* @return bool
*/
public static function setHooks( Parser $parser ) {
global $wgHooks;
@ -1325,8 +1315,6 @@ class Cite {
}
$parser->setHook( 'ref', [ $parser->extCite, 'ref' ] );
$parser->setHook( 'references', [ $parser->extCite, 'references' ] );
return true;
}
/**

View file

@ -15,7 +15,6 @@ class CiteHooks {
*
* @param Title $title
* @param string &$model
* @return bool
*/
public static function onContentHandlerDefaultModelFor( Title $title, &$model ) {
if (
@ -27,8 +26,6 @@ class CiteHooks {
) {
$model = CONTENT_MODEL_JSON;
}
return true;
}
/**
@ -37,7 +34,6 @@ class CiteHooks {
*
* @param array &$testModules The array of registered test modules
* @param ResourceLoader &$resourceLoader The reference to the resource loader
* @return true
*/
public static function onResourceLoaderTestModules(
array &$testModules,
@ -66,8 +62,6 @@ class CiteHooks {
'remoteExtPath' => 'Cite',
];
}
return true;
}
/**
@ -75,11 +69,10 @@ class CiteHooks {
* VisualEditor MediaWiki extension.
*
* @param ResourceLoader &$resourceLoader
* @return true
*/
public static function onResourceLoaderRegisterModules( &$resourceLoader ) {
if ( ! class_exists( 'VisualEditorHooks' ) ) {
return true;
return;
}
$dir = dirname( __DIR__ ) . DIRECTORY_SEPARATOR;
@ -246,7 +239,6 @@ class CiteHooks {
"mobile"
]
] );
return true;
}
/**
@ -319,13 +311,11 @@ class CiteHooks {
/**
* Adds extra variables to the global config
* @param array &$vars
* @return true
*/
public static function onResourceLoaderGetConfigVars( array &$vars ) {
$config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'cite' );
$vars['wgCiteVisualEditorOtherGroup'] = $config->get( 'CiteVisualEditorOtherGroup' );
$vars['wgCiteResponsiveReferences'] = $config->get( 'CiteResponsiveReferences' );
return true;
}
/**