wikimedia/mediawiki-core

View on GitHub

Showing 11,545 of 11,545 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

OO.ui.RadioInputWidget.prototype.restorePreInfuseState = function ( state ) {
    OO.ui.RadioInputWidget.super.prototype.restorePreInfuseState.call( this, state );
    if ( state.checked !== undefined && state.checked !== this.isSelected() ) {
        this.setSelected( state.checked );
    }
Severity: Major
Found in resources/lib/ooui/oojs-ui-core.js and 1 other location - About 3 hrs to fix
resources/lib/ooui/oojs-ui-core.js on lines 10538..10543

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 114.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Method getWatchedItemsWithRecentChangeInfo has 98 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getWatchedItemsWithRecentChangeInfo(
        User $user, array $options = [], &$startFrom = null
    ) {
        $options += [
            'includeFields' => [],
Severity: Major
Found in includes/watchlist/WatchedItemQueryService.php - About 3 hrs to fix

    File RollbackPage.php has 330 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: Minor
    Found in includes/page/RollbackPage.php - About 3 hrs to fix

      Method buildPersonalUrls has 98 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function buildPersonalUrls( bool $includeNotifications = true ) {
              $this->setupTemplateContext();
              $title = $this->getTitle();
              $authority = $this->getAuthority();
              $request = $this->getRequest();
      Severity: Major
      Found in includes/skins/SkinTemplate.php - About 3 hrs to fix

        Method loadFromDB has 98 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function loadFromDB( $code, $mode = null ) {
                $icp = MediaWikiServices::getInstance()->getConnectionProvider();
        
                $dbr = ( $mode === self::FOR_UPDATE ) ? $icp->getPrimaryDatabase() : $icp->getReplicaDatabase();
        
        
        Severity: Major
        Found in includes/language/MessageCache.php - About 3 hrs to fix

          Method formatNumInternal has 98 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function formatNumInternal(
                  string $number, bool $noTranslate, bool $noSeparators
              ): string {
                  $translateNumerals = $this->config->get( MainConfigNames::TranslateNumerals );
          
          
          Severity: Major
          Found in includes/language/Language.php - About 3 hrs to fix

            Method segmentSplitter has 98 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function segmentSplitter( $filename ) {
                    $showXMP = XMPReader::isSupported();
            
                    $segmentCount = 0;
            
            
            Severity: Major
            Found in includes/media/JpegMetadataExtractor.php - About 3 hrs to fix

              File LinkCache.php has 330 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              <?php
              /**
               * Page existence cache.
               *
               * This program is free software; you can redistribute it and/or modify
              Severity: Minor
              Found in includes/cache/LinkCache.php - About 3 hrs to fix

                Method getAllowedParams has 98 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function getAllowedParams() {
                        return [
                            'title' => null,
                            'text' => [
                                ParamValidator::PARAM_TYPE => 'text',
                Severity: Major
                Found in includes/api/ApiParse.php - About 3 hrs to fix

                  Method execute has 98 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function execute() {
                          $this->useTransactionalTimeLimit();
                  
                          $user = $this->getUser();
                          $params = $this->extractRequestParams();
                  Severity: Major
                  Found in includes/api/ApiMove.php - About 3 hrs to fix

                    Method execute has 98 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function execute() {
                            $params = $this->extractRequestParams();
                            $done = [];
                            foreach ( $params['prop'] as $p ) {
                                switch ( $p ) {
                    Severity: Major
                    Found in includes/api/ApiQuerySiteinfo.php - About 3 hrs to fix

                      Method outputPageList has 98 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          private function outputPageList( $groups ) {
                              $out = $this->getOutput();
                      
                              // Legend
                              $includesRestrictedPages = false;
                      Severity: Major
                      Found in includes/specials/SpecialSpecialPages.php - About 3 hrs to fix

                        Method execute has 98 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            public function execute( $par ) {
                                $user = $this->getUser();
                                $request = $this->getRequest();
                                $session = $request->getSession();
                                $out = $this->getOutput();
                        Severity: Major
                        Found in includes/specials/SpecialUserRights.php - About 3 hrs to fix

                          File LinkHolderArray.php has 330 lines of code (exceeds 250 allowed). Consider refactoring.
                          Open

                          <?php
                          /**
                           * Holder of replacement pairs for wiki links
                           *
                           * This program is free software; you can redistribute it and/or modify
                          Severity: Minor
                          Found in includes/parser/LinkHolderArray.php - About 3 hrs to fix

                            Function useFloating has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
                            Open

                            function useFloating(reference, floating, options) {
                              if (options === void 0) {
                                options = {};
                              }
                              const whileElementsMountedOption = options.whileElementsMounted;
                            Severity: Minor
                            Found in resources/lib/codex/codex.js - About 3 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

                            Function getNamespaceRestrictionLevels has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
                            Open

                                public function getNamespaceRestrictionLevels( $index, UserIdentity $user = null ): array {
                                    if ( !isset( $this->options->get( MainConfigNames::NamespaceProtection )[$index] ) ) {
                                        // All levels are valid if there's no namespace restriction.
                                        // But still filter by user, if necessary
                                        $levels = $this->options->get( MainConfigNames::RestrictionLevels );
                            Severity: Minor
                            Found in includes/Permissions/PermissionManager.php - About 3 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

                            Function generateContentOutput has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
                            Open

                                private function generateContentOutput(
                                    Authority $performer,
                                    ParserOptions $parserOptions,
                                    int $oldid,
                                    OutputPage $outputPage,
                            Severity: Minor
                            Found in includes/page/Article.php - About 3 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

                            Function prepareContent has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
                            Open

                                public function prepareContent(
                                    UserIdentity $user,
                                    RevisionSlotsUpdate $slotsUpdate,
                                    $useStash = true
                                ) {
                            Severity: Minor
                            Found in includes/Storage/DerivedPageDataUpdater.php - About 3 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

                            Function prepareUpdate has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
                            Open

                                public function prepareUpdate( RevisionRecord $revision, array $options = [] ) {
                                    Assert::parameter(
                                        !isset( $options['oldrevision'] )
                                        || $options['oldrevision'] instanceof RevisionRecord,
                                        '$options["oldrevision"]',
                            Severity: Minor
                            Found in includes/Storage/DerivedPageDataUpdater.php - About 3 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

                            Function doImport has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
                            Open

                                public function doImport() {
                                    $this->syntaxCheckXML();
                            
                                    // Calls to reader->read need to be wrapped in calls to
                                    // libxml_disable_entity_loader() to avoid local file
                            Severity: Minor
                            Found in includes/import/WikiImporter.php - About 3 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

                            Severity
                            Category
                            Status
                            Source
                            Language