wikimedia/mediawiki-core

View on GitHub
includes/libs/http/MultiHttpClient.php

Summary

Maintainability
F
4 days
Test Coverage

File MultiHttpClient.php has 479 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * HTTP service client
 *
 * This program is free software; you can redistribute it and/or modify
Severity: Minor
Found in includes/libs/http/MultiHttpClient.php - About 7 hrs to fix

    Method getCurlHandle has 108 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function getCurlHandle( array &$req, array $opts ) {
            $ch = curl_init();
    
            curl_setopt( $ch, CURLOPT_PROXY, $req['proxy'] ?? $this->proxy );
            curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT_MS, intval( $opts['connTimeout'] * 1e3 ) );
    Severity: Major
    Found in includes/libs/http/MultiHttpClient.php - About 4 hrs to fix

      Function runMultiHttp has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

          private function runMultiHttp( array $reqs, array $opts = [] ) {
              $httpOptions = [
                  'timeout' => $opts['reqTimeout'] ?? $this->reqTimeout,
                  'connectTimeout' => $opts['connTimeout'] ?? $this->connTimeout,
                  'logger' => $this->logger,
      Severity: Minor
      Found in includes/libs/http/MultiHttpClient.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 getCurlHandle has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function getCurlHandle( array &$req, array $opts ) {
              $ch = curl_init();
      
              curl_setopt( $ch, CURLOPT_PROXY, $req['proxy'] ?? $this->proxy );
              curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT_MS, intval( $opts['connTimeout'] * 1e3 ) );
      Severity: Minor
      Found in includes/libs/http/MultiHttpClient.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

      Method runMultiCurl has 69 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function runMultiCurl( array $reqs, array $opts ) {
              $chm = $this->getCurlMulti( $opts );
      
              $selectTimeout = $this->getSelectTimeout( $opts );
      
      
      Severity: Major
      Found in includes/libs/http/MultiHttpClient.php - About 2 hrs to fix

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

            private function normalizeRequests( array &$reqs ) {
                foreach ( $reqs as &$req ) {
                    $req['response'] = [
                        'code'     => 0,
                        'reason'   => '',
        Severity: Minor
        Found in includes/libs/http/MultiHttpClient.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 runMultiCurl has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

            private function runMultiCurl( array $reqs, array $opts ) {
                $chm = $this->getCurlMulti( $opts );
        
                $selectTimeout = $this->getSelectTimeout( $opts );
        
        
        Severity: Minor
        Found in includes/libs/http/MultiHttpClient.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 runMultiHttp has 59 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function runMultiHttp( array $reqs, array $opts = [] ) {
                $httpOptions = [
                    'timeout' => $opts['reqTimeout'] ?? $this->reqTimeout,
                    'connectTimeout' => $opts['connTimeout'] ?? $this->connTimeout,
                    'logger' => $this->logger,
        Severity: Major
        Found in includes/libs/http/MultiHttpClient.php - About 2 hrs to fix

          Method normalizeRequests has 51 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function normalizeRequests( array &$reqs ) {
                  foreach ( $reqs as &$req ) {
                      $req['response'] = [
                          'code'     => 0,
                          'reason'   => '',
          Severity: Major
          Found in includes/libs/http/MultiHttpClient.php - About 2 hrs to fix

            Function isLocalURL has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

                private function isLocalURL( $url ) {
                    if ( !$this->localVirtualHosts ) {
                        // Shortcut
                        return false;
                    }
            Severity: Minor
            Found in includes/libs/http/MultiHttpClient.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 runMulti has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function runMulti( array $reqs, array $opts = [] ) {
                    $this->normalizeRequests( $reqs );
                    $opts += [ 'connTimeout' => $this->connTimeout, 'reqTimeout' => $this->reqTimeout ];
            
                    if ( $this->maxConnTimeout && $opts['connTimeout'] > $this->maxConnTimeout ) {
            Severity: Minor
            Found in includes/libs/http/MultiHttpClient.php - About 1 hr to fix

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

                  public function runMulti( array $reqs, array $opts = [] ) {
                      $this->normalizeRequests( $reqs );
                      $opts += [ 'connTimeout' => $this->connTimeout, 'reqTimeout' => $this->reqTimeout ];
              
                      if ( $this->maxConnTimeout && $opts['connTimeout'] > $this->maxConnTimeout ) {
              Severity: Minor
              Found in includes/libs/http/MultiHttpClient.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 getCurlMulti has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  protected function getCurlMulti( array $opts ) {
                      if ( !$this->cmh ) {
                          $cmh = curl_multi_init();
                          // Limit the size of the idle connection cache such that consecutive parallel
                          // request batches to the same host can avoid having to keep making connections
              Severity: Minor
              Found in includes/libs/http/MultiHttpClient.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 strlen( $data );
              Severity: Major
              Found in includes/libs/http/MultiHttpClient.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                        return $ch;
                Severity: Major
                Found in includes/libs/http/MultiHttpClient.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                                      return fwrite( $req['stream'], $data );
                  Severity: Major
                  Found in includes/libs/http/MultiHttpClient.php - About 30 mins to fix

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

                        public function __construct( array $options ) {
                            if ( isset( $options['caBundlePath'] ) ) {
                                $this->caBundlePath = $options['caBundlePath'];
                                if ( !file_exists( $this->caBundlePath ) ) {
                                    throw new InvalidArgumentException( "Cannot find CA bundle: " . $this->caBundlePath );
                    Severity: Minor
                    Found in includes/libs/http/MultiHttpClient.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