wikimedia/mediawiki-core

View on GitHub
includes/api/ApiComparePages.php

Summary

Maintainability
F
1 wk
Test Coverage

Function getDiffRevision has a Cognitive Complexity of 97 (exceeds 5 allowed). Consider refactoring.
Open

    private function getDiffRevision( $prefix, array $params ) {
        // Back compat params
        $this->requireMaxOneParameter( $params, "{$prefix}text", "{$prefix}slots" );
        $this->requireMaxOneParameter( $params, "{$prefix}section", "{$prefix}slots" );
        if ( $params["{$prefix}text"] !== null ) {
Severity: Minor
Found in includes/api/ApiComparePages.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

File ApiComparePages.php has 618 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
Severity: Major
Found in includes/api/ApiComparePages.php - About 1 day to fix

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

        public function execute() {
            $params = $this->extractRequestParams();
    
            // Parameter validation
            $this->requireAtLeastOneParameter(
    Severity: Minor
    Found in includes/api/ApiComparePages.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 getDiffRevision has 178 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function getDiffRevision( $prefix, array $params ) {
            // Back compat params
            $this->requireMaxOneParameter( $params, "{$prefix}text", "{$prefix}slots" );
            $this->requireMaxOneParameter( $params, "{$prefix}section", "{$prefix}slots" );
            if ( $params["{$prefix}text"] !== null ) {
    Severity: Major
    Found in includes/api/ApiComparePages.php - About 7 hrs to fix

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

          private function setVals( &$vals, $prefix, $rev ) {
              if ( $rev ) {
                  $title = Title::newFromLinkTarget( $rev->getPageAsLinkTarget() );
                  if ( isset( $this->props['ids'] ) ) {
                      $vals["{$prefix}id"] = $title->getArticleID();
      Severity: Minor
      Found in includes/api/ApiComparePages.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

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

          public function execute() {
              $params = $this->extractRequestParams();
      
              // Parameter validation
              $this->requireAtLeastOneParameter(
      Severity: Major
      Found in includes/api/ApiComparePages.php - About 5 hrs to fix

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

            public function getAllowedParams() {
                $slotRoles = $this->slotRoleRegistry->getKnownRoles();
                sort( $slotRoles, SORT_STRING );
        
                // Parameters for the 'from' and 'to' content
        Severity: Major
        Found in includes/api/ApiComparePages.php - About 3 hrs to fix

          Function guessTitle has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
          Open

              private function guessTitle() {
                  if ( $this->guessedTitle !== false ) {
                      return $this->guessedTitle;
                  }
          
          
          Severity: Minor
          Found in includes/api/ApiComparePages.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 setVals has 60 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function setVals( &$vals, $prefix, $rev ) {
                  if ( $rev ) {
                      $title = Title::newFromLinkTarget( $rev->getPageAsLinkTarget() );
                      if ( isset( $this->props['ids'] ) ) {
                          $vals["{$prefix}id"] = $title->getArticleID();
          Severity: Major
          Found in includes/api/ApiComparePages.php - About 2 hrs to fix

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

                private function guessModel( $role ) {
                    $params = $this->extractRequestParams();
            
                    foreach ( [ 'from', 'to' ] as $prefix ) {
                        if ( $params["{$prefix}rev"] !== null ) {
            Severity: Minor
            Found in includes/api/ApiComparePages.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 __construct has 10 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                    ApiMain $mainModule,
                    $moduleName,
                    RevisionStore $revisionStore,
                    ArchivedRevisionLookup $archivedRevisionLookup,
                    SlotRoleRegistry $slotRoleRegistry,
            Severity: Major
            Found in includes/api/ApiComparePages.php - About 1 hr to fix

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

                  private function guessTitle() {
                      if ( $this->guessedTitle !== false ) {
                          return $this->guessedTitle;
                      }
              
              
              Severity: Minor
              Found in includes/api/ApiComparePages.php - About 1 hr to fix

                Method guessModel has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    private function guessModel( $role ) {
                        $params = $this->extractRequestParams();
                
                        foreach ( [ 'from', 'to' ] as $prefix ) {
                            if ( $params["{$prefix}rev"] !== null ) {
                Severity: Minor
                Found in includes/api/ApiComparePages.php - About 1 hr to fix

                  Avoid too many return statements within this method.
                  Open

                                  return $params['tocontentmodel'];
                  Severity: Major
                  Found in includes/api/ApiComparePages.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

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

                      Avoid too many return statements within this method.
                      Open

                                      return $params['fromcontentmodel'];
                      Severity: Major
                      Found in includes/api/ApiComparePages.php - About 30 mins to fix

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

                            public function getAllowedParams() {
                                $slotRoles = $this->slotRoleRegistry->getKnownRoles();
                                sort( $slotRoles, SORT_STRING );
                        
                                // Parameters for the 'from' and 'to' content
                        Severity: Minor
                        Found in includes/api/ApiComparePages.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