File Hooks.php
has 806 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* VisualEditor extension hooks
*
* @file
Function onSkinTemplateNavigation__Universal
has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring. Open
public function onSkinTemplateNavigation__Universal( $skin, &$links ): void {
$services = MediaWikiServices::getInstance();
$userOptionsLookup = $services->getUserOptionsLookup();
$config = $services->getConfigFactory()
->makeConfig( 'visualeditor' );
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method onSkinTemplateNavigation__Universal
has 151 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function onSkinTemplateNavigation__Universal( $skin, &$links ): void {
$services = MediaWikiServices::getInstance();
$userOptionsLookup = $services->getUserOptionsLookup();
$config = $services->getConfigFactory()
->makeConfig( 'visualeditor' );
Hooks
has 32 functions (exceeds 20 allowed). Consider refactoring. Open
class Hooks implements
TextSlotDiffRendererTablePrefixHook,
BeforeInitializeHook,
BeforePageDisplayHook,
ChangeTagsListActiveHook,
Method onSkinEditSectionLinks
has 81 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function onSkinEditSectionLinks( $skin, $title, $section,
$tooltip, &$result, $lang
) {
$services = MediaWikiServices::getInstance();
$userOptionsLookup = $services->getUserOptionsLookup();
Method onGetPreferences
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function onGetPreferences( $user, &$preferences ) {
$services = MediaWikiServices::getInstance();
$userOptionsLookup = $services->getUserOptionsLookup();
$veConfig = $services->getConfigFactory()->makeConfig( 'visualeditor' );
$isBeta = $veConfig->get( 'VisualEditorEnableBetaFeature' );
Method onResourceLoaderGetConfigVars
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function onResourceLoaderGetConfigVars( array &$vars, $skin, Config $config ): void {
$coreConfig = RequestContext::getMain()->getConfig();
$services = MediaWikiServices::getInstance();
$veConfig = $services->getConfigFactory()->makeConfig( 'visualeditor' );
$extensionRegistry = ExtensionRegistry::getInstance();
Consider simplifying this complex logical expression. Open
if (
$isAvailable &&
$config->get( 'VisualEditorUseSingleEditTab' ) &&
(
$userOptionsLookup->getOption( $user, 'visualeditor-tabs' ) === 'prefer-ve' ||
Function onSkinEditSectionLinks
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
public function onSkinEditSectionLinks( $skin, $title, $section,
$tooltip, &$result, $lang
) {
$services = MediaWikiServices::getInstance();
$userOptionsLookup = $services->getUserOptionsLookup();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method onBeforePageDisplay
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function onBeforePageDisplay( $output, $skin ): void {
$services = MediaWikiServices::getInstance();
$hookRunner = new VisualEditorHookRunner( $services->getHookContainer() );
if ( !$hookRunner->onVisualEditorBeforeEditor( $output, $skin ) ) {
$output->addJsConfigVars( 'wgVisualEditorDisabledByHook', true );
Method onCustomEditor
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function onCustomEditor( $article, $user ) {
$req = $article->getContext()->getRequest();
$services = MediaWikiServices::getInstance();
$urlUtils = $services->getUrlUtils();
$veConfig = $services->getConfigFactory()->makeConfig( 'visualeditor' );
Method onTextSlotDiffRendererTablePrefix
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function onTextSlotDiffRendererTablePrefix(
TextSlotDiffRenderer $textSlotDiffRenderer,
IContextSource $context,
array &$parts
) {
Method onSkinEditSectionLinks
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
public function onSkinEditSectionLinks( $skin, $title, $section,
$tooltip, &$result, $lang
Function onBeforePageDisplay
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function onBeforePageDisplay( $output, $skin ): void {
$services = MediaWikiServices::getInstance();
$hookRunner = new VisualEditorHookRunner( $services->getHookContainer() );
if ( !$hookRunner->onVisualEditorBeforeEditor( $output, $skin ) ) {
$output->addJsConfigVars( 'wgVisualEditorDisabledByHook', true );
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function onCustomEditor
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function onCustomEditor( $article, $user ) {
$req = $article->getContext()->getRequest();
$services = MediaWikiServices::getInstance();
$urlUtils = $services->getUrlUtils();
$veConfig = $services->getConfigFactory()->makeConfig( 'visualeditor' );
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method onBeforeInitialize
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
$title, $article, $output, $user, $request, $mediaWiki
Consider simplifying this complex logical expression. Open
if (
$config->get( 'VisualEditorUseSingleEditTab' ) &&
wfTimestampNow() < $config->get( 'VisualEditorSingleEditTabSwitchTimeEnd' ) &&
$user->isNamed() &&
self::enabledForUser( $user ) &&
Method onPreferencesFormPreSave
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function onPreferencesFormPreSave( $data, $form, $user, &$result, $oldUserOptions ) {
Avoid too many return
statements within this method. Open
return self::getLastEditor( $user, $req );
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return;
Avoid too many return
statements within this method. Open
return;
Function onGetPreferences
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function onGetPreferences( $user, &$preferences ) {
$services = MediaWikiServices::getInstance();
$userOptionsLookup = $services->getUserOptionsLookup();
$veConfig = $services->getConfigFactory()->makeConfig( 'visualeditor' );
$isBeta = $veConfig->get( 'VisualEditorEnableBetaFeature' );
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function isSupportedEditPage
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private static function isSupportedEditPage( Title $title, User $user, WebRequest $req ): bool {
if (
$req->getVal( 'action' ) !== 'edit' ||
!MediaWikiServices::getInstance()->getPermissionManager()->quickUserCan( 'edit', $user, $title )
) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"