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.SelectWidget.prototype.findFirstSelectedItem = function () {
    for ( let i = 0; i < this.items.length; i++ ) {
        if ( this.items[ i ].isSelected() ) {
            return this.items[ i ];
        }
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 7730..7737

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 99.

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

DerivativeContext has 27 functions (exceeds 20 allowed). Consider refactoring.
Open

class DerivativeContext extends Context {
    private const INHERIT_VALUE = -1;

    /**
     * @var Context
Severity: Minor
Found in includes/ResourceLoader/DerivativeContext.php - About 3 hrs to fix

    SqlBlobStore has 27 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class SqlBlobStore implements BlobStore {
    
        // Note: the name has been taken unchanged from the old Revision class.
        public const TEXT_CACHE_GROUP = 'revisiontext:10';
    
    
    Severity: Minor
    Found in includes/Storage/SqlBlobStore.php - About 3 hrs to fix

      MimeAnalyzer has 27 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class MimeAnalyzer implements LoggerAwareInterface {
          /** @var string */
          protected $typeFile;
          /** @var string */
          protected $infoFile;
      Severity: Minor
      Found in includes/libs/mime/MimeAnalyzer.php - About 3 hrs to fix

        PostgresUpdater has 27 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class PostgresUpdater extends DatabaseUpdater {
        
            /**
             * @var DatabasePostgres
             */
        Severity: Minor
        Found in includes/installer/PostgresUpdater.php - About 3 hrs to fix

          MainConfigSchema has 27 functions (exceeds 20 allowed). Consider refactoring.
          Open

          class MainConfigSchema {
              use JsonSchemaTrait;
          
              /**
               * Returns a generator for iterating over all config settings and their default values.
          Severity: Minor
          Found in includes/MainConfigSchema.php - About 3 hrs to fix

            HtmlOutputRendererHelper has 27 functions (exceeds 20 allowed). Consider refactoring.
            Open

            class HtmlOutputRendererHelper implements HtmlOutputHelper {
                use RestAuthorizeTrait;
                use RestStatusTrait;
            
                /**
            Severity: Minor
            Found in includes/Rest/Handler/Helper/HtmlOutputRendererHelper.php - About 3 hrs to fix

              Function updateUI has 79 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  mw.widgets.datetime.CalendarWidget.prototype.updateUI = function () {
                      let row, day, k, $cell,
                          width = this.minWidth;
              
                      const
              Severity: Major
              Found in resources/src/mediawiki.widgets.datetime/CalendarWidget.js - About 3 hrs to fix

                Function fetch has 79 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  function fetch(input, init) {
                    return new Promise(function(resolve, reject) {
                      var request = new Request(input, init);
                
                      if (request.signal && request.signal.aborted) {
                Severity: Major
                Found in resources/lib/fetch-polyfill/fetch.umd.js - About 3 hrs to fix

                  Method getButtons has 79 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function getButtons() {
                          $buttons = [];
                  
                          if ( $this->mShowSubmit ) {
                              $value = $this->getSubmitText();
                  Severity: Major
                  Found in includes/htmlform/CodexHTMLForm.php - About 3 hrs to fix

                    Method applyDefaultConfig has 79 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function applyDefaultConfig( array $lbConf ): array {
                            $this->options->assertRequiredOptions( self::APPLY_DEFAULT_CONFIG_OPTIONS );
                    
                            $typesWithSchema = self::getDbTypesWithSchemas();
                            if ( Profiler::instance() instanceof ProfilerStub ) {
                    Severity: Major
                    Found in includes/db/MWLBFactory.php - About 3 hrs to fix

                      Method processTitlesArray has 79 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          private function processTitlesArray( $titles ) {
                              $linkBatch = $this->linkBatchFactory->newLinkBatch();
                      
                              /** @var Title[] $titleObjects */
                              $titleObjects = [];
                      Severity: Major
                      Found in includes/api/ApiPageSet.php - About 3 hrs to fix

                        Method postHtml has 79 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            protected function postHtml() {
                                $links = [];
                        
                                $this->getOutput()->addModuleStyles( 'mediawiki.special' );
                        
                        
                        Severity: Major
                        Found in includes/specials/SpecialBlock.php - About 3 hrs to fix

                          Method doHeader has 79 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              public function doHeader( $opts, $numRows ) {
                                  $this->setTopText( $opts );
                          
                                  $defaults = $opts->getAllValues();
                                  $nondefaults = $opts->getChangedValues();
                          Severity: Major
                          Found in includes/specials/SpecialRecentChanges.php - About 3 hrs to fix

                            Method genParserOutput has 79 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                private function genParserOutput(
                                    PageConfig $pageConfig, ParserOptions $options, ?ParserOutput $previousOutput
                                ): ParserOutput {
                                    $parserOutput = new ParserOutput();
                            
                            
                            Severity: Major
                            Found in includes/parser/Parsoid/ParsoidParser.php - About 3 hrs to fix

                              Method stashFile has 79 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  public function stashFile( $path, $sourceType = null, $fileProps = null ) {
                                      if ( !is_file( $path ) ) {
                                          wfDebug( __METHOD__ . " tried to stash file at '$path', but it doesn't exist" );
                                          throw new UploadStashBadPathException(
                                              wfMessage( 'uploadstash-bad-path' )
                              Severity: Major
                              Found in includes/upload/UploadStash.php - About 3 hrs to fix

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

                                    public function execute() {
                                        # Change to current working directory
                                        $oldCwd = getcwd();
                                        chdir( $oldCwd );
                                
                                
                                Severity: Major
                                Found in maintenance/deleteBatch.php - About 3 hrs to fix

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

                                      public function execute() {
                                          if ( !$this->hasOption( 'unicode-data-file' ) ) {
                                              $dataFile = 'UnicodeData.txt';
                                              if ( !file_exists( $dataFile ) ) {
                                                  $this->fatalError( "Unable to find UnicodeData.txt. Please specify " .
                                  Severity: Major
                                  Found in maintenance/language/generateNormalizerDataAr.php - About 3 hrs to fix

                                    Method __construct has 79 lines of code (exceeds 25 allowed). Consider refactoring.
                                    Open

                                        public function __construct() {
                                            parent::__construct();
                                    
                                            $this->addDescription( 'Imports images and other media files into the wiki' );
                                            $this->addArg( 'dir', 'Path to the directory containing images to be imported' );
                                    Severity: Major
                                    Found in maintenance/importImages.php - About 3 hrs to fix

                                      Method doReassignEdits has 79 lines of code (exceeds 25 allowed). Consider refactoring.
                                      Open

                                          private function doReassignEdits( &$from, &$to, $updateRC = false, $report = false ) {
                                              $dbw = $this->getPrimaryDB();
                                              $this->beginTransaction( $dbw, __METHOD__ );
                                              $actorNormalization = $this->getServiceContainer()->getActorNormalization();
                                              $fromActorId = $actorNormalization->findActorId( $from, $dbw );
                                      Severity: Major
                                      Found in maintenance/reassignEdits.php - About 3 hrs to fix
                                        Severity
                                        Category
                                        Status
                                        Source
                                        Language