wikimedia/mediawiki-core

View on GitHub
includes/preferences/DefaultPreferencesFactory.php

Summary

Maintainability
F
2 wks
Test Coverage

File DefaultPreferencesFactory.php has 1521 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
Severity: Major
Found in includes/preferences/DefaultPreferencesFactory.php - About 4 days to fix

    Method profilePreferences has 421 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function profilePreferences(
            User $user, IContextSource $context, &$defaultPreferences
        ) {
            // retrieving user name for GENDER and misc.
            $userName = $user->getName();
    Severity: Major
    Found in includes/preferences/DefaultPreferencesFactory.php - About 2 days to fix

      Function profilePreferences has a Cognitive Complexity of 82 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function profilePreferences(
              User $user, IContextSource $context, &$defaultPreferences
          ) {
              // retrieving user name for GENDER and misc.
              $userName = $user->getName();
      Severity: Minor
      Found in includes/preferences/DefaultPreferencesFactory.php - About 1 day 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 watchlistPreferences has 143 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function watchlistPreferences(
              User $user, IContextSource $context, &$defaultPreferences
          ) {
              $watchlistdaysMax = ceil( $this->options->get( MainConfigNames::RCMaxAge ) / ( 3600 * 24 ) );
      
      
      Severity: Major
      Found in includes/preferences/DefaultPreferencesFactory.php - About 5 hrs to fix

        Method rcPreferences has 87 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function rcPreferences( User $user, MessageLocalizer $l10n, &$defaultPreferences ) {
                $rcMaxAge = $this->options->get( MainConfigNames::RCMaxAge );
                $rcMax = ceil( $rcMaxAge / ( 3600 * 24 ) );
                $defaultPreferences['rcdays'] = [
                    'type' => 'float',
        Severity: Major
        Found in includes/preferences/DefaultPreferencesFactory.php - About 3 hrs to fix

          DefaultPreferencesFactory has 28 functions (exceeds 20 allowed). Consider refactoring.
          Open

          class DefaultPreferencesFactory implements PreferencesFactory {
              use LoggerAwareTrait;
          
              /** @var ServiceOptions */
              protected $options;
          Severity: Minor
          Found in includes/preferences/DefaultPreferencesFactory.php - About 3 hrs to fix

            Function getOptionFromUser has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function getOptionFromUser( $name, $info, array $userOptions ) {
                    $val = $userOptions[$name] ?? null;
            
                    // Handling for multiselect preferences
                    if ( ( isset( $info['type'] ) && $info['type'] == 'multiselect' ) ||
            Severity: Minor
            Found in includes/preferences/DefaultPreferencesFactory.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 editingPreferences has 65 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected function editingPreferences( User $user, MessageLocalizer $l10n, &$defaultPreferences ) {
                    $defaultPreferences['editsectiononrightclick'] = [
                        'type' => 'toggle',
                        'section' => 'editing/advancedediting',
                        'label-message' => 'tog-editsectiononrightclick',
            Severity: Major
            Found in includes/preferences/DefaultPreferencesFactory.php - About 2 hrs to fix

              Function skinPreferences has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
              Open

                  protected function skinPreferences( User $user, IContextSource $context, &$defaultPreferences ) {
                      // Skin selector, if there is at least one valid skin
                      $validSkinNames = $this->getValidSkinNames( $user, $context );
                      if ( $validSkinNames ) {
                          $defaultPreferences['skin'] = [
              Severity: Minor
              Found in includes/preferences/DefaultPreferencesFactory.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 searchPreferences has 59 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function searchPreferences( $context, &$defaultPreferences ) {
                      $defaultPreferences['search-special-page'] = [
                          'type' => 'api',
                      ];
              
              
              Severity: Major
              Found in includes/preferences/DefaultPreferencesFactory.php - About 2 hrs to fix

                Method skinPreferences has 58 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    protected function skinPreferences( User $user, IContextSource $context, &$defaultPreferences ) {
                        // Skin selector, if there is at least one valid skin
                        $validSkinNames = $this->getValidSkinNames( $user, $context );
                        if ( $validSkinNames ) {
                            $defaultPreferences['skin'] = [
                Severity: Major
                Found in includes/preferences/DefaultPreferencesFactory.php - About 2 hrs to fix

                  Method datetimePreferences has 49 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      protected function datetimePreferences(
                          User $user, IContextSource $context, &$defaultPreferences
                      ) {
                          $dateOptions = $this->getDateOptions( $context );
                          if ( $dateOptions ) {
                  Severity: Minor
                  Found in includes/preferences/DefaultPreferencesFactory.php - About 1 hr to fix

                    Function simplifyFormDescriptor has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public static function simplifyFormDescriptor( array $descriptor ) {
                            foreach ( $descriptor as $name => &$params ) {
                                // Info fields are useless and can use complicated closure to provide
                                // text, skip all of them.
                                if ( ( isset( $params['type'] ) && $params['type'] === 'info' ) ||
                    Severity: Minor
                    Found in includes/preferences/DefaultPreferencesFactory.php - About 1 hr 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 __construct has 15 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                            ServiceOptions $options,
                            Language $contLang,
                            AuthManager $authManager,
                            LinkRenderer $linkRenderer,
                            NamespaceInfo $nsInfo,
                    Severity: Major
                    Found in includes/preferences/DefaultPreferencesFactory.php - About 1 hr to fix

                      Function generateSkinOptions has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                      Open

                          protected function generateSkinOptions( User $user, IContextSource $context, array $validSkinNames ) {
                              $ret = [];
                      
                              $mptitle = Title::newMainPage();
                              $previewtext = $context->msg( 'skin-preview' )->escaped();
                      Severity: Minor
                      Found in includes/preferences/DefaultPreferencesFactory.php - About 1 hr 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 renderingPreferences has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          protected function renderingPreferences(
                              User $user,
                              MessageLocalizer $l10n,
                              &$defaultPreferences
                          ) {
                      Severity: Minor
                      Found in includes/preferences/DefaultPreferencesFactory.php - About 1 hr to fix

                        Method generateSkinOptions has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            protected function generateSkinOptions( User $user, IContextSource $context, array $validSkinNames ) {
                                $ret = [];
                        
                                $mptitle = Title::newMainPage();
                                $previewtext = $context->msg( 'skin-preview' )->escaped();
                        Severity: Minor
                        Found in includes/preferences/DefaultPreferencesFactory.php - About 1 hr to fix

                          Method saveFormData has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              protected function saveFormData( $formData, PreferencesFormOOUI $form, array $formDescriptor ) {
                                  $user = $form->getModifiedUser();
                                  $hiddenPrefs = $this->options->get( MainConfigNames::HiddenPrefs );
                                  $result = true;
                          
                          
                          Severity: Minor
                          Found in includes/preferences/DefaultPreferencesFactory.php - About 1 hr to fix

                            Function loadPreferenceValues has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                            Open

                                private function loadPreferenceValues( User $user, IContextSource $context, &$defaultPreferences ) {
                                    // Remove preferences that wikis don't want to use
                                    foreach ( $this->options->get( MainConfigNames::HiddenPrefs ) as $pref ) {
                                        unset( $defaultPreferences[$pref] );
                                    }
                            Severity: Minor
                            Found in includes/preferences/DefaultPreferencesFactory.php - About 1 hr 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 validateSignature has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                            Open

                                protected function validateSignature( $signature, $alldata, HTMLForm $form ) {
                                    $sigValidation = $this->options->get( MainConfigNames::SignatureValidation );
                                    $maxSigChars = $this->options->get( MainConfigNames::MaxSigChars );
                                    if ( is_string( $signature ) && mb_strlen( $signature ) > $maxSigChars ) {
                                        return $form->msg( 'badsiglength' )->numParams( $maxSigChars )->escaped();
                            Severity: Minor
                            Found in includes/preferences/DefaultPreferencesFactory.php - About 1 hr 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 saveFormData has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                            Open

                                protected function saveFormData( $formData, PreferencesFormOOUI $form, array $formDescriptor ) {
                                    $user = $form->getModifiedUser();
                                    $hiddenPrefs = $this->options->get( MainConfigNames::HiddenPrefs );
                                    $result = true;
                            
                            
                            Severity: Minor
                            Found in includes/preferences/DefaultPreferencesFactory.php - About 1 hr 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 loadPreferenceValues has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                private function loadPreferenceValues( User $user, IContextSource $context, &$defaultPreferences ) {
                                    // Remove preferences that wikis don't want to use
                                    foreach ( $this->options->get( MainConfigNames::HiddenPrefs ) as $pref ) {
                                        unset( $defaultPreferences[$pref] );
                                    }
                            Severity: Minor
                            Found in includes/preferences/DefaultPreferencesFactory.php - About 1 hr to fix

                              Function getDateOptions has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  protected function getDateOptions( IContextSource $context ) {
                                      $lang = $context->getLanguage();
                                      $dateopts = $lang->getDatePreferences();
                              
                                      $ret = [];
                              Severity: Minor
                              Found in includes/preferences/DefaultPreferencesFactory.php - About 1 hr 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 validateSignature has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  protected function validateSignature( $signature, $alldata, HTMLForm $form ) {
                                      $sigValidation = $this->options->get( MainConfigNames::SignatureValidation );
                                      $maxSigChars = $this->options->get( MainConfigNames::MaxSigChars );
                                      if ( is_string( $signature ) && mb_strlen( $signature ) > $maxSigChars ) {
                                          return $form->msg( 'badsiglength' )->numParams( $maxSigChars )->escaped();
                              Severity: Minor
                              Found in includes/preferences/DefaultPreferencesFactory.php - About 1 hr to fix

                                Method getForm has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                    public function getForm(
                                        User $user,
                                        IContextSource $context,
                                        $formClass = PreferencesFormOOUI::class,
                                        array $remove = []
                                Severity: Minor
                                Found in includes/preferences/DefaultPreferencesFactory.php - About 1 hr to fix

                                  Function applyFilters has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      protected function applyFilters( array &$preferences, array $formDescriptor, $verb ) {
                                          foreach ( $formDescriptor as $preference => $desc ) {
                                              if ( !isset( $desc['filter'] ) || !isset( $preferences[$preference] ) ) {
                                                  continue;
                                              }
                                  Severity: Minor
                                  Found in includes/preferences/DefaultPreferencesFactory.php - About 1 hr 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 sortSkinNames has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      private static function sortSkinNames( $a, $b, $currentSkin, $preferredSkins ) {
                                          // Display the current skin first in the list
                                          if ( strcasecmp( $a, $currentSkin ) === 0 ) {
                                              return -1;
                                          }
                                  Severity: Minor
                                  Found in includes/preferences/DefaultPreferencesFactory.php - About 1 hr 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 watchlistPreferences has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      protected function watchlistPreferences(
                                          User $user, IContextSource $context, &$defaultPreferences
                                      ) {
                                          $watchlistdaysMax = ceil( $this->options->get( MainConfigNames::RCMaxAge ) / ( 3600 * 24 ) );
                                  
                                  
                                  Severity: Minor
                                  Found in includes/preferences/DefaultPreferencesFactory.php - About 1 hr 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 getOptionFromUser has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                      protected function getOptionFromUser( $name, $info, array $userOptions ) {
                                          $val = $userOptions[$name] ?? null;
                                  
                                          // Handling for multiselect preferences
                                          if ( ( isset( $info['type'] ) && $info['type'] == 'multiselect' ) ||
                                  Severity: Minor
                                  Found in includes/preferences/DefaultPreferencesFactory.php - About 1 hr to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                    return strcasecmp( $aPreferred, $bPreferred );
                                    Severity: Major
                                    Found in includes/preferences/DefaultPreferencesFactory.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                              return strcasecmp( $a, $b );
                                      Severity: Major
                                      Found in includes/preferences/DefaultPreferencesFactory.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                    return $form->msg( 'badsig' )->escaped();
                                        Severity: Major
                                        Found in includes/preferences/DefaultPreferencesFactory.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

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

                                            Avoid too many return statements within this method.
                                            Open

                                                            return $errors;
                                            Severity: Major
                                            Found in includes/preferences/DefaultPreferencesFactory.php - About 30 mins to fix

                                              Function getPreferenceForField has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                                  public static function getPreferenceForField( $name, HTMLFormField $field, array $userOptions ) {
                                                      $val = $userOptions[$name] ?? null;
                                              
                                                      if ( $field instanceof HTMLNestedFilterable ) {
                                                          $val = [];
                                              Severity: Minor
                                              Found in includes/preferences/DefaultPreferencesFactory.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 getValidSkinNames has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                                  private function getValidSkinNames( User $user, IContextSource $context ) {
                                                      // Only show skins that aren't disabled
                                                      $validSkinNames = $this->skinFactory->getAllowedSkins();
                                                      $allInstalledSkins = $this->skinFactory->getInstalledSkins();
                                              
                                              
                                              Severity: Minor
                                              Found in includes/preferences/DefaultPreferencesFactory.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