wikimedia/mediawiki-extensions-VisualEditor

View on GitHub
includes/Hooks.php

Summary

Maintainability
F
6 days
Test Coverage

File Hooks.php has 806 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * VisualEditor extension hooks
 *
 * @file
Severity: Major
Found in includes/Hooks.php - About 1 day to fix

    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' );
    Severity: Minor
    Found in includes/Hooks.php - About 6 hrs to fix

    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' );
    Severity: Major
    Found in includes/Hooks.php - About 6 hrs to fix

      Hooks has 32 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Hooks implements
          TextSlotDiffRendererTablePrefixHook,
          BeforeInitializeHook,
          BeforePageDisplayHook,
          ChangeTagsListActiveHook,
      Severity: Minor
      Found in includes/Hooks.php - About 4 hrs to fix

        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();
        Severity: Major
        Found in includes/Hooks.php - About 3 hrs to fix

          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' );
          Severity: Major
          Found in includes/Hooks.php - About 2 hrs to fix

            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();
            Severity: Major
            Found in includes/Hooks.php - About 2 hrs to fix

              Consider simplifying this complex logical expression.
              Open

                              if (
                                  $isAvailable &&
                                  $config->get( 'VisualEditorUseSingleEditTab' ) &&
                                  (
                                      $userOptionsLookup->getOption( $user, 'visualeditor-tabs' ) === 'prefer-ve' ||
              Severity: Critical
              Found in includes/Hooks.php - About 2 hrs to fix

                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();
                Severity: Minor
                Found in includes/Hooks.php - About 2 hrs to fix

                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 );
                Severity: Minor
                Found in includes/Hooks.php - About 1 hr to fix

                  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' );
                  Severity: Minor
                  Found in includes/Hooks.php - About 1 hr to fix

                    Method onTextSlotDiffRendererTablePrefix has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function onTextSlotDiffRendererTablePrefix(
                            TextSlotDiffRenderer $textSlotDiffRenderer,
                            IContextSource $context,
                            array &$parts
                        ) {
                    Severity: Minor
                    Found in includes/Hooks.php - About 1 hr to fix

                      Method onSkinEditSectionLinks has 6 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          public function onSkinEditSectionLinks( $skin, $title, $section,
                              $tooltip, &$result, $lang
                      Severity: Minor
                      Found in includes/Hooks.php - About 45 mins to fix

                        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 );
                        Severity: Minor
                        Found in includes/Hooks.php - About 45 mins to fix

                        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' );
                        Severity: Minor
                        Found in includes/Hooks.php - About 45 mins to fix

                        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
                        Severity: Minor
                        Found in includes/Hooks.php - About 45 mins to fix

                          Consider simplifying this complex logical expression.
                          Open

                                  if (
                                      $config->get( 'VisualEditorUseSingleEditTab' ) &&
                                      wfTimestampNow() < $config->get( 'VisualEditorSingleEditTabSwitchTimeEnd' ) &&
                                      $user->isNamed() &&
                                      self::enabledForUser( $user ) &&
                          Severity: Major
                          Found in includes/Hooks.php - About 40 mins to fix

                            Method onPreferencesFormPreSave has 5 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                                public function onPreferencesFormPreSave( $data, $form, $user, &$result, $oldUserOptions ) {
                            Severity: Minor
                            Found in includes/Hooks.php - About 35 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                              return self::getLastEditor( $user, $req );
                              Severity: Major
                              Found in includes/Hooks.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                        return true;
                                Severity: Major
                                Found in includes/Hooks.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                              return;
                                  Severity: Major
                                  Found in includes/Hooks.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                return;
                                    Severity: Major
                                    Found in includes/Hooks.php - About 30 mins to fix

                                      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' );
                                      Severity: Minor
                                      Found in includes/Hooks.php - About 25 mins to fix

                                      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 )
                                              ) {
                                      Severity: Minor
                                      Found in includes/Hooks.php - About 25 mins to fix

                                      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

                                      There are no issues that match your filters.

                                      Category
                                      Status