wikimedia/mediawiki-core

View on GitHub
includes/api/ApiPageSet.php

Summary

Maintainability
F
1 wk
Test Coverage

File ApiPageSet.php has 958 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Copyright © 2006, 2013 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
 *
 * This program is free software; you can redistribute it and/or modify
Severity: Major
Found in includes/api/ApiPageSet.php - About 2 days to fix

    ApiPageSet has 65 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ApiPageSet extends ApiBase {
        /**
         * Constructor flag: The new instance of ApiPageSet will ignore the 'generator=' parameter
         * @since 1.21
         */
    Severity: Major
    Found in includes/api/ApiPageSet.php - About 1 day to fix

      Function populateGeneratorData has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
      Open

          public function populateGeneratorData( &$result, array $path = [] ) {
              if ( $result instanceof ApiResult ) {
                  $data = $result->getResultData( $path );
                  if ( $data === null ) {
                      return true;
      Severity: Minor
      Found in includes/api/ApiPageSet.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

      Function processTitlesArray has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
      Open

          private function processTitlesArray( $titles ) {
              $linkBatch = $this->linkBatchFactory->newLinkBatch();
      
              /** @var Title[] $titleObjects */
              $titleObjects = [];
      Severity: Minor
      Found in includes/api/ApiPageSet.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

      Function executeInternal has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
      Open

          private function executeInternal( $isDryRun ) {
              $generatorName = $this->mAllowGenerator ? $this->mParams['generator'] : null;
              if ( isset( $generatorName ) ) {
                  $dbSource = $this->mDbSource;
                  if ( !$dbSource instanceof ApiQuery ) {
      Severity: Minor
      Found in includes/api/ApiPageSet.php - About 6 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 initFromQueryResult has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
      Open

          private function initFromQueryResult( $res, &$remaining = null, $processTitles = null ) {
              if ( $remaining !== null && $processTitles === null ) {
                  ApiBase::dieDebug( __METHOD__, 'Missing $processTitles parameter when $remaining is provided' );
              }
      
      
      Severity: Minor
      Found in includes/api/ApiPageSet.php - About 5 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 executeInternal has 83 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function executeInternal( $isDryRun ) {
              $generatorName = $this->mAllowGenerator ? $this->mParams['generator'] : null;
              if ( isset( $generatorName ) ) {
                  $dbSource = $this->mDbSource;
                  if ( !$dbSource instanceof ApiQuery ) {
      Severity: Major
      Found in includes/api/ApiPageSet.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 populateGeneratorData has 69 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function populateGeneratorData( &$result, array $path = [] ) {
                  if ( $result instanceof ApiResult ) {
                      $data = $result->getResultData( $path );
                      if ( $data === null ) {
                          return true;
          Severity: Major
          Found in includes/api/ApiPageSet.php - About 2 hrs to fix

            Method initFromRevIDs has 63 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function initFromRevIDs( $revids ) {
                    if ( !$revids ) {
                        return;
                    }
            
            
            Severity: Major
            Found in includes/api/ApiPageSet.php - About 2 hrs to fix

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

                  public function getInvalidTitlesAndRevisions( $invalidChecks = [ 'invalidTitles',
                      'special', 'missingIds', 'missingRevIds', 'missingTitles', 'interwikiTitles' ]
                  ) {
                      $result = [];
                      if ( in_array( 'invalidTitles', $invalidChecks ) ) {
              Severity: Minor
              Found in includes/api/ApiPageSet.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

              Function initFromRevIDs has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function initFromRevIDs( $revids ) {
                      if ( !$revids ) {
                          return;
                      }
              
              
              Severity: Minor
              Found in includes/api/ApiPageSet.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 loadRedirectTargets has 51 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function loadRedirectTargets() {
                      $titlesToResolve = [];
                      $db = $this->getDB();
              
                      if ( $this->mPendingRedirectIDs ) {
              Severity: Major
              Found in includes/api/ApiPageSet.php - About 2 hrs to fix

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

                    private function loadRedirectTargets() {
                        $titlesToResolve = [];
                        $db = $this->getDB();
                
                        if ( $this->mPendingRedirectIDs ) {
                Severity: Minor
                Found in includes/api/ApiPageSet.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 initFromQueryResult has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    private function initFromQueryResult( $res, &$remaining = null, $processTitles = null ) {
                        if ( $remaining !== null && $processTitles === null ) {
                            ApiBase::dieDebug( __METHOD__, 'Missing $processTitles parameter when $remaining is provided' );
                        }
                
                
                Severity: Minor
                Found in includes/api/ApiPageSet.php - About 1 hr to fix

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

                      public function getAllowedParams( $flags = 0 ) {
                          $result = [
                              'titles' => [
                                  ParamValidator::PARAM_ISMULTI => true,
                                  ApiBase::PARAM_HELP_MSG => 'api-pageset-param-titles',
                  Severity: Minor
                  Found in includes/api/ApiPageSet.php - About 1 hr to fix

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

                        public function getInvalidTitlesAndRevisions( $invalidChecks = [ 'invalidTitles',
                            'special', 'missingIds', 'missingRevIds', 'missingTitles', 'interwikiTitles' ]
                        ) {
                            $result = [];
                            if ( in_array( 'invalidTitles', $invalidChecks ) ) {
                    Severity: Minor
                    Found in includes/api/ApiPageSet.php - About 1 hr to fix

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

                          public function getRedirectTitlesAsResult( $result = null ) {
                              $values = [];
                              foreach ( $this->getRedirectTitles() as $titleStrFrom => $titleTo ) {
                                  $r = [
                                      'from' => strval( $titleStrFrom ),
                      Severity: Minor
                      Found in includes/api/ApiPageSet.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 resolvePendingRedirects has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                      Open

                          private function resolvePendingRedirects() {
                              if ( $this->mResolveRedirects ) {
                                  $db = $this->getDB();
                      
                                  // Repeat until all redirects have been resolved
                      Severity: Minor
                      Found in includes/api/ApiPageSet.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 getRedirectTitlesAsResult has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function getRedirectTitlesAsResult( $result = null ) {
                              $values = [];
                              foreach ( $this->getRedirectTitles() as $titleStrFrom => $titleTo ) {
                                  $r = [
                                      'from' => strval( $titleStrFrom ),
                      Severity: Minor
                      Found in includes/api/ApiPageSet.php - About 1 hr to fix

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

                            private function getGenerators() {
                                if ( self::$generators === null ) {
                                    $query = $this->mDbSource;
                                    if ( !( $query instanceof ApiQuery ) ) {
                                        // If the parent container of this pageset is not ApiQuery,
                        Severity: Minor
                        Found in includes/api/ApiPageSet.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

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

                            private static function addValues( array &$result, $values, $flags = [], $name = null ) {
                                foreach ( $values as $val ) {
                                    if ( $val instanceof Title ) {
                                        $v = [];
                                        ApiQueryBase::addTitleInfo( $v, $val );
                        Severity: Minor
                        Found in includes/api/ApiPageSet.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 true;
                        Severity: Major
                        Found in includes/api/ApiPageSet.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                  return null;
                          Severity: Major
                          Found in includes/api/ApiPageSet.php - About 30 mins to fix

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

                                public function handleParamNormalization( $paramName, $value, $rawValue ) {
                                    parent::handleParamNormalization( $paramName, $value, $rawValue );
                            
                                    if ( $paramName === 'titles' ) {
                                        // For the 'titles' parameter, we want to split it like ApiBase would
                            Severity: Minor
                            Found in includes/api/ApiPageSet.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