wikimedia/mediawiki-core

View on GitHub
includes/libs/objectcache/utils/MemcachedClient.php

Summary

Maintainability
F
6 days
Test Coverage

File MemcachedClient.php has 627 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
// phpcs:ignoreFile -- It's an external lib and it isn't. Let's not bother.
/**
 * Memcached client for PHP.
 *
Severity: Major
Found in includes/libs/objectcache/utils/MemcachedClient.php - About 1 day to fix

    MemcachedClient has 38 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class MemcachedClient implements StorageAwareness {
        // {{{ properties
        // {{{ public
    
        // {{{ constants
    Severity: Minor
    Found in includes/libs/objectcache/utils/MemcachedClient.php - About 5 hrs to fix

      Function _load_items has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

          function _load_items( $sock, &$ret, &$casToken = null ) {
              $results = array();
      
              while ( 1 ) {
                  $decl = $this->_fgets( $sock );
      Severity: Minor
      Found in includes/libs/objectcache/utils/MemcachedClient.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 _set has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          function _set( $cmd, $key, $val, $exp, $casToken = null ) {
              $this->_last_cmd_status = self::ERR_NONE;
      
              if ( !$this->_active ) {
                  $this->_last_cmd_status = self::ERR_UNEXPECTED;
      Severity: Minor
      Found in includes/libs/objectcache/utils/MemcachedClient.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 get_multi has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          public function get_multi( $keys ) {
              $this->_last_cmd_status = self::ERR_NONE;
      
              if ( !$this->_active ) {
                  $this->_last_cmd_status = self::ERR_UNEXPECTED;
      Severity: Minor
      Found in includes/libs/objectcache/utils/MemcachedClient.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 _set has 61 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          function _set( $cmd, $key, $val, $exp, $casToken = null ) {
              $this->_last_cmd_status = self::ERR_NONE;
      
              if ( !$this->_active ) {
                  $this->_last_cmd_status = self::ERR_UNEXPECTED;
      Severity: Major
      Found in includes/libs/objectcache/utils/MemcachedClient.php - About 2 hrs to fix

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

            function get_sock( $key ) {
                if ( !$this->_active ) {
                    return false;
                }
        
        
        Severity: Minor
        Found in includes/libs/objectcache/utils/MemcachedClient.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 get_multi has 51 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function get_multi( $keys ) {
                $this->_last_cmd_status = self::ERR_NONE;
        
                if ( !$this->_active ) {
                    $this->_last_cmd_status = self::ERR_UNEXPECTED;
        Severity: Major
        Found in includes/libs/objectcache/utils/MemcachedClient.php - About 2 hrs to fix

          Method get has 46 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function get( $key, &$casToken = null ) {
                  $getToken = ( func_num_args() >= 2 );
          
                  $this->_last_cmd_status = self::ERR_NONE;
          
          
          Severity: Minor
          Found in includes/libs/objectcache/utils/MemcachedClient.php - About 1 hr to fix

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

                public function get( $key, &$casToken = null ) {
                    $getToken = ( func_num_args() >= 2 );
            
                    $this->_last_cmd_status = self::ERR_NONE;
            
            
            Severity: Minor
            Found in includes/libs/objectcache/utils/MemcachedClient.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 _load_items has 36 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                function _load_items( $sock, &$ret, &$casToken = null ) {
                    $results = array();
            
                    while ( 1 ) {
                        $decl = $this->_fgets( $sock );
            Severity: Minor
            Found in includes/libs/objectcache/utils/MemcachedClient.php - About 1 hr to fix

              Method _connect_sock has 32 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  function _connect_sock( &$sock, $host ) {
                      $port = null;
                      $hostAndPort = IPUtils::splitHostAndPort( $host );
                      if ( $hostAndPort ) {
                          $ip = $hostAndPort[0];
              Severity: Minor
              Found in includes/libs/objectcache/utils/MemcachedClient.php - About 1 hr to fix

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

                    function _connect_sock( &$sock, $host ) {
                        $port = null;
                        $hostAndPort = IPUtils::splitHostAndPort( $host );
                        if ( $hostAndPort ) {
                            $ip = $hostAndPort[0];
                Severity: Minor
                Found in includes/libs/objectcache/utils/MemcachedClient.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 get_sock has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    function get_sock( $key ) {
                        if ( !$this->_active ) {
                            return false;
                        }
                
                
                Severity: Minor
                Found in includes/libs/objectcache/utils/MemcachedClient.php - About 1 hr to fix

                  Method _incrdecr has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      function _incrdecr( $cmd, $key, $amt = 1 ) {
                          $this->_last_cmd_status = self::ERR_NONE;
                  
                          if ( !$this->_active ) {
                              $this->_last_cmd_status = self::ERR_UNEXPECTED;
                  Severity: Minor
                  Found in includes/libs/objectcache/utils/MemcachedClient.php - About 1 hr to fix

                    Method delete has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function delete( $key, $time = 0 ) {
                            $this->_last_cmd_status = self::ERR_NONE;
                    
                            if ( !$this->_active ) {
                                return false;
                    Severity: Minor
                    Found in includes/libs/objectcache/utils/MemcachedClient.php - About 1 hr to fix

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

                          public function touch( $key, $time = 0 ) {
                              $this->_last_cmd_status = self::ERR_NONE;
                      
                              if ( !$this->_active ) {
                                  return false;
                      Severity: Minor
                      Found in includes/libs/objectcache/utils/MemcachedClient.php - About 1 hr to fix

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

                            public function run_command( $sock, $cmd ) {
                                if ( !$sock ) {
                                    return array();
                                }
                        
                        
                        Severity: Minor
                        Found in includes/libs/objectcache/utils/MemcachedClient.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 delete has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                            public function delete( $key, $time = 0 ) {
                                $this->_last_cmd_status = self::ERR_NONE;
                        
                                if ( !$this->_active ) {
                                    return false;
                        Severity: Minor
                        Found in includes/libs/objectcache/utils/MemcachedClient.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 sock_to_host has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                            function sock_to_host( $host ) {
                                if ( isset( $this->_cache_sock[$host] ) ) {
                                    return $this->_cache_sock[$host];
                                }
                        
                        
                        Severity: Minor
                        Found in includes/libs/objectcache/utils/MemcachedClient.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

                        Method _set has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            function _set( $cmd, $key, $val, $exp, $casToken = null ) {
                        Severity: Minor
                        Found in includes/libs/objectcache/utils/MemcachedClient.php - About 35 mins to fix

                          Function touch has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                              public function touch( $key, $time = 0 ) {
                                  $this->_last_cmd_status = self::ERR_NONE;
                          
                                  if ( !$this->_active ) {
                                      return false;
                          Severity: Minor
                          Found in includes/libs/objectcache/utils/MemcachedClient.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 _incrdecr has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                              function _incrdecr( $cmd, $key, $amt = 1 ) {
                                  $this->_last_cmd_status = self::ERR_NONE;
                          
                                  if ( !$this->_active ) {
                                      $this->_last_cmd_status = self::ERR_UNEXPECTED;
                          Severity: Minor
                          Found in includes/libs/objectcache/utils/MemcachedClient.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 _fread has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                              function _fread( $sock, $len ) {
                                  $buf = '';
                                  while ( $len > 0 ) {
                                      $result = fread( $sock, $len );
                                      $data = stream_get_meta_data( $sock );
                          Severity: Minor
                          Found in includes/libs/objectcache/utils/MemcachedClient.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 false;
                          Severity: Major
                          Found in includes/libs/objectcache/utils/MemcachedClient.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                        return true;
                            Severity: Major
                            Found in includes/libs/objectcache/utils/MemcachedClient.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                      return (int)$match[1];
                              Severity: Major
                              Found in includes/libs/objectcache/utils/MemcachedClient.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                        return $value;
                                Severity: Major
                                Found in includes/libs/objectcache/utils/MemcachedClient.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                          return false;
                                  Severity: Major
                                  Found in includes/libs/objectcache/utils/MemcachedClient.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                            return false;
                                    Severity: Major
                                    Found in includes/libs/objectcache/utils/MemcachedClient.php - About 30 mins to fix

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

                                          function _fwrite( $sock, $buf ) {
                                              $bytesWritten = 0;
                                              $bufSize = strlen( $buf );
                                              while ( $bytesWritten < $bufSize ) {
                                                  $result = fwrite( $sock, $buf );
                                      Severity: Minor
                                      Found in includes/libs/objectcache/utils/MemcachedClient.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