wikimedia/mediawiki-extensions-CirrusSearch

View on GitHub
maintenance/ForceSearchIndex.php

Summary

Maintainability
F
3 days
Test Coverage

File ForceSearchIndex.php has 516 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace CirrusSearch\Maintenance;

use BatchRowIterator;
Severity: Major
Found in maintenance/ForceSearchIndex.php - About 1 day to fix

    Function execute has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

        public function execute() {
            $this->disablePoolCountersAndLogging();
            $wiki = sprintf( "[%20s]", WikiMap::getCurrentWikiId() );
    
            // Make sure we've actually got indices to populate
    Severity: Minor
    Found in maintenance/ForceSearchIndex.php - About 4 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 execute has 94 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function execute() {
            $this->disablePoolCountersAndLogging();
            $wiki = sprintf( "[%20s]", WikiMap::getCurrentWikiId() );
    
            // Make sure we've actually got indices to populate
    Severity: Major
    Found in maintenance/ForceSearchIndex.php - About 3 hrs to fix

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

          public function __construct() {
              parent::__construct();
              $this->addDescription( "Force indexing some pages.  Setting --from or --to will switch "
                  . "from page id based indexing to "
                  . "date based indexing which uses less efficient queries and follows redirects.\n\n"
      Severity: Major
      Found in maintenance/ForceSearchIndex.php - About 2 hrs to fix

        Method getDeletesIterator has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function getDeletesIterator() {
                $dbr = $this->getDB( DB_REPLICA, [ 'vslow' ] );
                $it = new BatchRowIterator(
                    $dbr,
                    'logging',
        Severity: Minor
        Found in maintenance/ForceSearchIndex.php - About 1 hr to fix

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

              private function decidePage( Updater $updater, WikiPage $page ) {
                  try {
                      $content = $page->getContent();
                  } catch ( Throwable $ex ) {
                      LoggerFactory::getInstance( 'CirrusSearch' )->warning(
          Severity: Minor
          Found in maintenance/ForceSearchIndex.php - About 1 hr to fix

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

                private function buildChunks( $buildChunks ) {
                    $dbr = $this->getDB( DB_REPLICA, [ 'vslow' ] );
                    if ( $this->toId === null ) {
                        $this->toId = $dbr->newSelectQueryBuilder()
                            ->select( 'MAX(page_id)' )
            Severity: Minor
            Found in maintenance/ForceSearchIndex.php - About 1 hr to fix

              Function waitForQueueToDrain has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function waitForQueueToDrain( $wiki ) {
                      if ( !$this->queue ) {
                          return;
                      }
              
              
              Severity: Minor
              Found in maintenance/ForceSearchIndex.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

              Consider simplifying this complex logical expression.
              Open

                      if ( !$this->indexUpdates || $this->hasOption( 'limit' )
                          || $this->hasOption( 'from' ) || $this->hasOption( 'to' )
                          || $this->hasOption( 'fromId' ) || $this->hasOption( 'toId' )
                      ) {
                          $this->fatalError(
              Severity: Major
              Found in maintenance/ForceSearchIndex.php - About 40 mins to fix

                Function wrapDecodeResults has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    private function wrapDecodeResults( BatchRowIterator $it, $endingAtColumn ) {
                        return new CallbackIterator( $it, function ( $batch ) use ( $endingAtColumn ) {
                            // Build the updater outside the loop because it stores the redirects it hits.
                            // Don't build it at the top level so those are stored when it is freed.
                            $updater = $this->createUpdater();
                Severity: Minor
                Found in maintenance/ForceSearchIndex.php - About 35 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 buildChunks has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    private function buildChunks( $buildChunks ) {
                        $dbr = $this->getDB( DB_REPLICA, [ 'vslow' ] );
                        if ( $this->toId === null ) {
                            $this->toId = $dbr->newSelectQueryBuilder()
                                ->select( 'MAX(page_id)' )
                Severity: Minor
                Found in maintenance/ForceSearchIndex.php - About 35 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

                Avoid too many return statements within this method.
                Open

                            return null;
                Severity: Major
                Found in maintenance/ForceSearchIndex.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                          return $page;
                  Severity: Major
                  Found in maintenance/ForceSearchIndex.php - About 30 mins to fix

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

                        private function decidePage( Updater $updater, WikiPage $page ) {
                            try {
                                $content = $page->getContent();
                            } catch ( Throwable $ex ) {
                                LoggerFactory::getInstance( 'CirrusSearch' )->warning(
                    Severity: Minor
                    Found in maintenance/ForceSearchIndex.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