wikimedia/mediawiki-core

View on GitHub
includes/api/ApiBase.php

Summary

Maintainability
F
1 wk
Test Coverage

File ApiBase.php has 1061 lines of code (exceeds 250 allowed). Consider refactoring.
Open

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

    ApiBase has 79 functions (exceeds 20 allowed). Consider refactoring.
    Open

    abstract class ApiBase extends ContextSource {
    
        use ApiBlockInfoTrait;
    
        /** @var HookContainer */
    Severity: Major
    Found in includes/api/ApiBase.php - About 1 day to fix

      Function extractRequestParams has a Cognitive Complexity of 69 (exceeds 5 allowed). Consider refactoring.
      Open

          public function extractRequestParams( $options = [] ) {
              if ( is_bool( $options ) ) {
                  $options = [ 'parseLimit' => $options ];
              }
              $options += [
      Severity: Minor
      Found in includes/api/ApiBase.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 getFinalParamDescription has a Cognitive Complexity of 62 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getFinalParamDescription() {
              $prefix = $this->getModulePrefix();
              $name = $this->getModuleName();
              $path = $this->getModulePath();
      
      
      Severity: Minor
      Found in includes/api/ApiBase.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

      Method getFinalParamDescription has 124 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function getFinalParamDescription() {
              $prefix = $this->getModulePrefix();
              $name = $this->getModuleName();
              $path = $this->getModulePath();
      
      
      Severity: Major
      Found in includes/api/ApiBase.php - About 4 hrs to fix

        Method extractRequestParams has 84 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function extractRequestParams( $options = [] ) {
                if ( is_bool( $options ) ) {
                    $options = [ 'parseLimit' => $options ];
                }
                $options += [
        Severity: Major
        Found in includes/api/ApiBase.php - About 3 hrs to fix

          Function getModuleSourceInfo has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function getModuleSourceInfo() {
                  if ( $this->mModuleSource !== false ) {
                      return $this->mModuleSource;
                  }
          
          
          Severity: Minor
          Found in includes/api/ApiBase.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 getModuleSourceInfo has 53 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function getModuleSourceInfo() {
                  if ( $this->mModuleSource !== false ) {
                      return $this->mModuleSource;
                  }
          
          
          Severity: Major
          Found in includes/api/ApiBase.php - About 2 hrs to fix

            Function getTitleOrPageId has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                public function getTitleOrPageId( $params, $load = false ) {
                    $this->requireOnlyOneParameter( $params, 'title', 'pageid' );
            
                    $pageObj = null;
                    if ( isset( $params['title'] ) ) {
            Severity: Minor
            Found in includes/api/ApiBase.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 dieStatus has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

                public function dieStatus( StatusValue $status ) {
                    if ( $status->isGood() ) {
                        throw new InvalidArgumentException( 'Successful status passed to ApiBase::dieStatus' );
                    }
            
            
            Severity: Minor
            Found in includes/api/ApiBase.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 dieStatus has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function dieStatus( StatusValue $status ) {
                    if ( $status->isGood() ) {
                        throw new InvalidArgumentException( 'Successful status passed to ApiBase::dieStatus' );
                    }
            
            
            Severity: Minor
            Found in includes/api/ApiBase.php - About 1 hr to fix

              Function getWatchlistUser has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function getWatchlistUser( $params ) {
                      if ( $params['owner'] !== null && $params['token'] !== null ) {
                          $services = MediaWikiServices::getInstance();
                          $user = $services->getUserFactory()->newFromName( $params['owner'], UserRigorOptions::RIGOR_NONE );
                          if ( !$user || !$user->isRegistered() ) {
              Severity: Minor
              Found in includes/api/ApiBase.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 getModuleFromPath has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function getModuleFromPath( $path ) {
                      $module = $this->getMain();
                      if ( $path === 'main' ) {
                          return $module;
                      }
              Severity: Minor
              Found in includes/api/ApiBase.php - About 1 hr to fix

                Function requirePostedParameters has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function requirePostedParameters( $params, $prefix = 'prefix' ) {
                        if ( !$this->mustBePosted() ) {
                            // In order to allow client code to choose the correct method (GET or POST) depending *only*
                            // on mustBePosted(), make sure that the module requires posting if any of its potential
                            // parameters require posting.
                Severity: Minor
                Found in includes/api/ApiBase.php - About 55 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 errorArrayToStatus has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function errorArrayToStatus( array $errors, Authority $performer = null ) {
                        $performer ??= $this->getAuthority();
                        $block = $performer->getBlock();
                
                        $status = Status::newGood();
                Severity: Minor
                Found in includes/api/ApiBase.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 getModuleFromPath has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function getModuleFromPath( $path ) {
                        $module = $this->getMain();
                        if ( $path === 'main' ) {
                            return $module;
                        }
                Severity: Minor
                Found in includes/api/ApiBase.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 getTitleFromTitleOrPageId has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function getTitleFromTitleOrPageId( $params ) {
                        $this->requireOnlyOneParameter( $params, 'title', 'pageid' );
                
                        $titleObj = null;
                        if ( isset( $params['title'] ) ) {
                Severity: Minor
                Found in includes/api/ApiBase.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 parseContinueParamOrDie has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    protected function parseContinueParamOrDie( string $continue, array $types ): array {
                        $cont = explode( '|', $continue );
                        $this->dieContinueUsageIf( count( $cont ) != count( $types ) );
                
                        foreach ( $cont as $i => &$value ) {
                Severity: Minor
                Found in includes/api/ApiBase.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 checkTitleUserPermissions has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function checkTitleUserPermissions(
                        PageIdentity $pageIdentity,
                        $actions,
                        array $options = []
                    ) {
                Severity: Minor
                Found in includes/api/ApiBase.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 addBlockInfoToStatus has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function addBlockInfoToStatus( StatusValue $status, Authority $user = null ) {
                        if ( $status instanceof PermissionStatus ) {
                            $block = $status->getBlock();
                        } else {
                            $user = $user ?: $this->getAuthority();
                Severity: Minor
                Found in includes/api/ApiBase.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

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

                                if ( isset( $settings[SubmoduleDef::PARAM_SUBMODULE_MAP] ) ) {
                                    $map = $settings[SubmoduleDef::PARAM_SUBMODULE_MAP];
                                } else {
                                    $prefix = $this->isMain() ? '' : ( $this->getModulePath() . '+' );
                                    $map = [];
                Severity: Minor
                Found in includes/api/ApiBase.php and 1 other location - About 35 mins to fix
                includes/api/Validator/SubmoduleDef.php on lines 141..149

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

                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

                There are no issues that match your filters.

                Category
                Status