wikimedia/mediawiki-extensions-CirrusSearch

View on GitHub
includes/Updater.php

Summary

Maintainability
D
1 day
Test Coverage

Function updateLinkedArticles has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

    public function updateLinkedArticles( $titles ): void {
        $pages = [];
        $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory();
        foreach ( $titles as $title ) {
            // Special pages don't get updated, we only index
Severity: Minor
Found in includes/Updater.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

File Updater.php has 304 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace CirrusSearch;

use CirrusSearch\BuildDocument\BuildDocument;
Severity: Minor
Found in includes/Updater.php - About 3 hrs to fix

    Function traceRedirects has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        public function traceRedirects( $title ) {
            // Loop through redirects until we get to the ultimate target
            $redirects = [];
            $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory();
            while ( true ) {
    Severity: Minor
    Found in includes/Updater.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 updatePages has 46 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function updatePages( $pages, $flags, string $updateKind = null, int $rootEventTime = null ): int {
            // Don't update the same page twice. We shouldn't, but meh
            $pageIds = [];
            $pages = array_filter( $pages, static function ( WikiPage $page ) use ( &$pageIds ) {
                if ( !in_array( $page->getId(), $pageIds ) ) {
    Severity: Minor
    Found in includes/Updater.php - About 1 hr to fix

      Method traceRedirects has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function traceRedirects( $title ) {
              // Loop through redirects until we get to the ultimate target
              $redirects = [];
              $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory();
              while ( true ) {
      Severity: Minor
      Found in includes/Updater.php - About 1 hr to fix

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

            public function updateLinkedArticles( $titles ): void {
                $pages = [];
                $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory();
                foreach ( $titles as $title ) {
                    // Special pages don't get updated, we only index
        Severity: Minor
        Found in includes/Updater.php - About 1 hr to fix

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

              protected function pushElasticaWriteJobs( string $updateGroup, array $items, $factory, int $batchSize = 10 ): void {
                  // Elasticsearch has a queue capacity of 50 so if $documents contains 50 pages it could bump up
                  // against the max.  So we chunk it and do them sequentially.
                  $jobs = [];
                  $config = $this->connection->getConfig();
          Severity: Minor
          Found in includes/Updater.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

          Avoid too many return statements within this method.
          Open

                              return [ null, $redirects ];
          Severity: Major
          Found in includes/Updater.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                            return [ $page, $redirects ];
            Severity: Major
            Found in includes/Updater.php - About 30 mins to fix

              There are no issues that match your filters.

              Category
              Status