wikimedia/mediawiki-core

View on GitHub
includes/api/ApiResult.php

Summary

Maintainability
F
6 days
Test Coverage

Function applyTransformations has a Cognitive Complexity of 72 (exceeds 5 allowed). Consider refactoring.
Open

    protected static function applyTransformations( array $dataIn, array $transforms ) {
        $strip = $transforms['Strip'] ?? 'none';
        if ( $strip === 'base' ) {
            $transforms['Strip'] = 'none';
        }
Severity: Minor
Found in includes/api/ApiResult.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 ApiResult.php has 630 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/ApiResult.php - About 1 day to fix

    Method applyTransformations has 184 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected static function applyTransformations( array $dataIn, array $transforms ) {
            $strip = $transforms['Strip'] ?? 'none';
            if ( $strip === 'base' ) {
                $transforms['Strip'] = 'none';
            }
    Severity: Major
    Found in includes/api/ApiResult.php - About 7 hrs to fix

      ApiResult has 40 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class ApiResult implements ApiSerializable {
      
          /**
           * Override existing value in addValue(), setValue(), and similar functions
           * @since 1.21
      Severity: Minor
      Found in includes/api/ApiResult.php - About 5 hrs to fix

        Function validateValue has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
        Open

            private static function validateValue( $value ) {
                if ( is_object( $value ) ) {
                    // Note we use is_callable() here instead of instanceof because
                    // ApiSerializable is an informal protocol (see docs there for details).
                    if ( is_callable( [ $value, 'serializeForApiResult' ] ) ) {
        Severity: Minor
        Found in includes/api/ApiResult.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

        Function setValue has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function setValue( array &$arr, $name, $value, $flags = 0 ) {
                if ( ( $flags & self::NO_VALIDATE ) !== self::NO_VALIDATE ) {
                    $value = self::validateValue( $value );
                }
        
        
        Severity: Minor
        Found in includes/api/ApiResult.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 validateValue has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private static function validateValue( $value ) {
                if ( is_object( $value ) ) {
                    // Note we use is_callable() here instead of instanceof because
                    // ApiSerializable is an informal protocol (see docs there for details).
                    if ( is_callable( [ $value, 'serializeForApiResult' ] ) ) {
        Severity: Minor
        Found in includes/api/ApiResult.php - About 1 hr to fix

          Function stripMetadata has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function stripMetadata( $data ) {
                  if ( is_array( $data ) || is_object( $data ) ) {
                      $isObj = is_object( $data );
                      if ( $isObj ) {
                          $data = (array)$data;
          Severity: Minor
          Found in includes/api/ApiResult.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 stripMetadataNonRecursive has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function stripMetadataNonRecursive( $data, &$metadata = null ) {
                  if ( !is_array( $metadata ) ) {
                      $metadata = [];
                  }
                  if ( is_array( $data ) || is_object( $data ) ) {
          Severity: Minor
          Found in includes/api/ApiResult.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 addMetadataToResultVars has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function addMetadataToResultVars( $vars, $forceHash = true ) {
                  // Process subarrays and determine if this is a JS [] or {}
                  $hash = $forceHash;
                  $maxKey = -1;
                  $bools = [];
          Severity: Minor
          Found in includes/api/ApiResult.php - About 1 hr to fix

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

                public static function addMetadataToResultVars( $vars, $forceHash = true ) {
                    // Process subarrays and determine if this is a JS [] or {}
                    $hash = $forceHash;
                    $maxKey = -1;
                    $bools = [];
            Severity: Minor
            Found in includes/api/ApiResult.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 setValue has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function setValue( array &$arr, $name, $value, $flags = 0 ) {
                    if ( ( $flags & self::NO_VALIDATE ) !== self::NO_VALIDATE ) {
                        $value = self::validateValue( $value );
                    }
            
            
            Severity: Minor
            Found in includes/api/ApiResult.php - About 1 hr to fix

              Method path has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function &path( $path, $create = 'append' ) {
                      $path = (array)$path;
                      $ret = &$this->data;
                      foreach ( $path as $i => $k ) {
                          if ( !isset( $ret[$k] ) ) {
              Severity: Minor
              Found in includes/api/ApiResult.php - About 1 hr to fix

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

                    private function &path( $path, $create = 'append' ) {
                        $path = (array)$path;
                        $ret = &$this->data;
                        foreach ( $path as $i => $k ) {
                            if ( !isset( $ret[$k] ) ) {
                Severity: Minor
                Found in includes/api/ApiResult.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 size has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    private static function size( $value ) {
                        $s = 0;
                        if ( is_array( $value ) ) {
                            foreach ( $value as $k => $v ) {
                                if ( !self::isMetadataKey( $k ) ) {
                Severity: Minor
                Found in includes/api/ApiResult.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 $data + $keepMetadata;
                Severity: Major
                Found in includes/api/ApiResult.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                                  return $ret + $keepMetadata;
                  Severity: Major
                  Found in includes/api/ApiResult.php - About 30 mins to fix

                    There are no issues that match your filters.

                    Category
                    Status