wikimedia/mediawiki-extensions-CirrusSearch

View on GitHub
includes/ElasticaErrorHandler.php

Summary

Maintainability
D
2 days
Test Coverage

Method classifyError has 71 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function classifyError( \Elastica\Exception\ExceptionInterface $exception = null ) {
        if ( $exception === null ) {
            return 'unknown';
        }
        $error = self::extractFullError( $exception );
Severity: Major
Found in includes/ElasticaErrorHandler.php - About 2 hrs to fix

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

        public static function extractFullError( \Elastica\Exception\ExceptionInterface $exception ): array {
            if ( $exception instanceof BulkResponseException ) {
                $actionReasons = [];
                foreach ( $exception->getActionExceptions() as $actionException ) {
                    $actionReasons[] = $actionException->getMessage() . ': '
    Severity: Minor
    Found in includes/ElasticaErrorHandler.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 extractFullError has 63 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function extractFullError( \Elastica\Exception\ExceptionInterface $exception ): array {
            if ( $exception instanceof BulkResponseException ) {
                $actionReasons = [];
                foreach ( $exception->getActionExceptions() as $actionException ) {
                    $actionReasons[] = $actionException->getMessage() . ': '
    Severity: Major
    Found in includes/ElasticaErrorHandler.php - About 2 hrs to fix

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

          public static function extractMessageAndStatus( \Elastica\Exception\ExceptionInterface $exception = null ) {
              if ( !$exception ) {
                  return [ Status::newFatal( 'cirrussearch-backend-error' ), '' ];
              }
      
      
      Severity: Major
      Found in includes/ElasticaErrorHandler.php - About 2 hrs to fix

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

            public static function extractMessageAndStatus( \Elastica\Exception\ExceptionInterface $exception = null ) {
                if ( !$exception ) {
                    return [ Status::newFatal( 'cirrussearch-backend-error' ), '' ];
                }
        
        
        Severity: Minor
        Found in includes/ElasticaErrorHandler.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

        File ElasticaErrorHandler.php has 255 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        <?php
        
        namespace CirrusSearch;
        
        use Elastica\Exception\Bulk\ResponseException as BulkResponseException;
        Severity: Minor
        Found in includes/ElasticaErrorHandler.php - About 2 hrs to fix

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

              public static function classifyError( \Elastica\Exception\ExceptionInterface $exception = null ) {
                  if ( $exception === null ) {
                      return 'unknown';
                  }
                  $error = self::extractFullError( $exception );
          Severity: Minor
          Found in includes/ElasticaErrorHandler.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 formatMessage has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              protected static function formatMessage( array $error ) {
                  if ( isset( $error['actionReasons'] ) ) {
                      $message = $error['type'] . ': ' . $error['reason'];
                      foreach ( $error['actionReasons'] as $actionReason ) {
                          $message .= "  - $actionReason\n";
          Severity: Minor
          Found in includes/ElasticaErrorHandler.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 [ $status, 'Regex syntax error:  ' . $syntaxError ];
          Severity: Major
          Found in includes/ElasticaErrorHandler.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                        return [
                            Status::newFatal( 'cirrussearch-backend-error' ),
                            $formattedMessage
                        ];
            Severity: Major
            Found in includes/ElasticaErrorHandler.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return $error;
              Severity: Major
              Found in includes/ElasticaErrorHandler.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                        return "unknown";
                Severity: Major
                Found in includes/ElasticaErrorHandler.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                          return [
                              Status::newFatal( 'cirrussearch-backend-error' ),
                              self::formatMessage( $cause )
                          ];
                  Severity: Major
                  Found in includes/ElasticaErrorHandler.php - About 30 mins to fix

                    There are no issues that match your filters.

                    Category
                    Status