wikimedia/mediawiki-core

View on GitHub
includes/libs/rdbms/loadbalancer/LoadBalancer.php

Summary

Maintainability
F
1 wk
Test Coverage

File LoadBalancer.php has 1339 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/libs/rdbms/loadbalancer/LoadBalancer.php - About 3 days to fix

    LoadBalancer has 83 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class LoadBalancer implements ILoadBalancerForOwner {
        /** @var ILoadMonitor */
        private $loadMonitor;
        /** @var BagOStuff */
        private $srvCache;
    Severity: Major
    Found in includes/libs/rdbms/loadbalancer/LoadBalancer.php - About 1 day to fix

      Function reuseOrOpenConnectionForNewRef has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

          private function reuseOrOpenConnectionForNewRef( $i, DatabaseDomain $domain, $flags = 0 ) {
              // Figure out which connection pool to use based on the flags
              if ( $this->fieldHasBit( $flags, self::CONN_UNTRACKED_GAUGE ) ) {
                  // Use low timeouts, use autocommit mode, ignore transaction rounds
                  $category = self::CATEGORY_GAUGE;
      Severity: Minor
      Found in includes/libs/rdbms/loadbalancer/LoadBalancer.php - About 4 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 reallyOpenConnection has 82 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function reallyOpenConnection( $i, DatabaseDomain $domain, array $lbInfo ) {
              if ( $this->disabled ) {
                  throw new DBAccessError();
              }
      
      
      Severity: Major
      Found in includes/libs/rdbms/loadbalancer/LoadBalancer.php - About 3 hrs to fix

        Function reallyOpenConnection has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function reallyOpenConnection( $i, DatabaseDomain $domain, array $lbInfo ) {
                if ( $this->disabled ) {
                    throw new DBAccessError();
                }
        
        
        Severity: Minor
        Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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 reuseOrOpenConnectionForNewRef has 54 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function reuseOrOpenConnectionForNewRef( $i, DatabaseDomain $domain, $flags = 0 ) {
                // Figure out which connection pool to use based on the flags
                if ( $this->fieldHasBit( $flags, self::CONN_UNTRACKED_GAUGE ) ) {
                    // Use low timeouts, use autocommit mode, ignore transaction rounds
                    $category = self::CATEGORY_GAUGE;
        Severity: Major
        Found in includes/libs/rdbms/loadbalancer/LoadBalancer.php - About 2 hrs to fix

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

              public function reconfigure( array $params ) {
                  $anyServerDepooled = false;
          
                  $paramServers = $params['servers'];
                  $newIndexByServerIndex = $this->serverInfo->reconfigureServers( $paramServers );
          Severity: Minor
          Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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 awaitSessionPrimaryPos has 52 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function awaitSessionPrimaryPos( $index, $timeout = null ) {
                  $timeout = max( 1, intval( $timeout ?: self::MAX_WAIT_DEFAULT ) );
          
                  if ( !$this->waitForPos || $index === ServerInfo::WRITER_INDEX ) {
                      return true;
          Severity: Major
          Found in includes/libs/rdbms/loadbalancer/LoadBalancer.php - About 2 hrs to fix

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

                protected function configure( array $params ): void {
                    $this->localDomain = isset( $params['localDomain'] )
                        ? DatabaseDomain::newFromId( $params['localDomain'] )
                        : DatabaseDomain::newUnspecified();
            
            
            Severity: Major
            Found in includes/libs/rdbms/loadbalancer/LoadBalancer.php - About 2 hrs to fix

              Method runPrimaryTransactionIdleCallbacks has 48 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function runPrimaryTransactionIdleCallbacks( $fname = __METHOD__ ) {
                      if ( $this->trxRoundStage === self::ROUND_COMMIT_CALLBACKS ) {
                          $type = IDatabase::TRIGGER_COMMIT;
                      } elseif ( $this->trxRoundStage === self::ROUND_ROLLBACK_CALLBACKS ) {
                          $type = IDatabase::TRIGGER_ROLLBACK;
              Severity: Minor
              Found in includes/libs/rdbms/loadbalancer/LoadBalancer.php - About 1 hr to fix

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

                    private function pickReaderIndex( array $loads ) {
                        if ( $loads === [] ) {
                            throw new InvalidArgumentException( "Server configuration array is empty" );
                        }
                
                
                Severity: Minor
                Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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 approvePrimaryChanges has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function approvePrimaryChanges( int $maxWriteDuration, $fname = __METHOD__ ) {
                        $this->assertTransactionRoundStage( self::ROUND_FINALIZED );
                        /** @noinspection PhpUnusedLocalVariableInspection */
                        $scope = ScopedCallback::newScopedIgnoreUserAbort();
                
                
                Severity: Minor
                Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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 runPrimaryTransactionIdleCallbacks has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function runPrimaryTransactionIdleCallbacks( $fname = __METHOD__ ) {
                        if ( $this->trxRoundStage === self::ROUND_COMMIT_CALLBACKS ) {
                            $type = IDatabase::TRIGGER_COMMIT;
                        } elseif ( $this->trxRoundStage === self::ROUND_ROLLBACK_CALLBACKS ) {
                            $type = IDatabase::TRIGGER_ROLLBACK;
                Severity: Minor
                Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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 approvePrimaryChanges has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function approvePrimaryChanges( int $maxWriteDuration, $fname = __METHOD__ ) {
                        $this->assertTransactionRoundStage( self::ROUND_FINALIZED );
                        /** @noinspection PhpUnusedLocalVariableInspection */
                        $scope = ScopedCallback::newScopedIgnoreUserAbort();
                
                
                Severity: Minor
                Found in includes/libs/rdbms/loadbalancer/LoadBalancer.php - About 1 hr to fix

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

                      private function resolveGroups( $groups, $i ) {
                          // If a specific replica server was specified, then $groups makes no sense
                          if ( $i > 0 && $groups !== [] && $groups !== false ) {
                              $list = implode( ', ', (array)$groups );
                              throw new LogicException( "Query group(s) ($list) given with server index (#$i)" );
                  Severity: Minor
                  Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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 reportConnectionError has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      private function reportConnectionError( $extraLbError = '' ) {
                          if ( $this->lastErrorConn instanceof IDatabase ) {
                              $srvName = $this->lastErrorConn->getServerName();
                              $lastDbError = $this->lastErrorConn->lastError() ?: 'unknown error';
                  
                  
                  Severity: Minor
                  Found in includes/libs/rdbms/loadbalancer/LoadBalancer.php - About 1 hr to fix

                    Method pickReaderIndex has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        private function pickReaderIndex( array $loads ) {
                            if ( $loads === [] ) {
                                throw new InvalidArgumentException( "Server configuration array is empty" );
                            }
                    
                    
                    Severity: Minor
                    Found in includes/libs/rdbms/loadbalancer/LoadBalancer.php - About 1 hr to fix

                      Method waitForPrimaryPos has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function waitForPrimaryPos( IDatabase $conn ) {
                              if ( $conn->getLBInfo( self::INFO_SERVER_INDEX ) === ServerInfo::WRITER_INDEX ) {
                                  return true; // not a replica DB server
                              }
                      
                      
                      Severity: Minor
                      Found in includes/libs/rdbms/loadbalancer/LoadBalancer.php - About 1 hr to fix

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

                            public function waitForPrimaryPos( IDatabase $conn ) {
                                if ( $conn->getLBInfo( self::INFO_SERVER_INDEX ) === ServerInfo::WRITER_INDEX ) {
                                    return true; // not a replica DB server
                                }
                        
                        
                        Severity: Minor
                        Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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 awaitSessionPrimaryPos has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                        Open

                            private function awaitSessionPrimaryPos( $index, $timeout = null ) {
                                $timeout = max( 1, intval( $timeout ?: self::MAX_WAIT_DEFAULT ) );
                        
                                if ( !$this->waitForPos || $index === ServerInfo::WRITER_INDEX ) {
                                    return true;
                        Severity: Minor
                        Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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 configure has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                        Open

                            protected function configure( array $params ): void {
                                $this->localDomain = isset( $params['localDomain'] )
                                    ? DatabaseDomain::newFromId( $params['localDomain'] )
                                    : DatabaseDomain::newUnspecified();
                        
                        
                        Severity: Minor
                        Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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 waitForAll has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            public function waitForAll( DBPrimaryPos $pos, $timeout = null ) {
                                $timeout = $timeout ?: self::MAX_WAIT_DEFAULT;
                        
                                $oldPos = $this->waitForPos;
                                try {
                        Severity: Minor
                        Found in includes/libs/rdbms/loadbalancer/LoadBalancer.php - About 1 hr to fix

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

                              private function isPrimaryRunningReadOnly( IDatabase $conn = null ) {
                                  // Context will often be HTTP GET/HEAD; heavily cache the results
                                  return (bool)$this->wanCache->getWithSetCallback(
                                      // Note that table prefixes are not related to server-side read-only mode
                                      $this->wanCache->makeGlobalKey(
                          Severity: Minor
                          Found in includes/libs/rdbms/loadbalancer/LoadBalancer.php - About 1 hr to fix

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

                                private function getRandomNonLagged( array $loads, $maxLag = INF ) {
                                    $lags = $this->getLagTimes();
                            
                                    # Unset excessively lagged servers
                                    foreach ( $lags as $i => $lag ) {
                            Severity: Minor
                            Found in includes/libs/rdbms/loadbalancer/LoadBalancer.php - About 1 hr to fix

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

                                  public function getReaderIndex( $group = false ) {
                                      $group = is_string( $group ) ? $group : self::GROUP_GENERIC;
                              
                                      if ( !$this->serverInfo->hasReplicaServers() ) {
                                          // There is only one possible server to use (the primary)
                              Severity: Minor
                              Found in includes/libs/rdbms/loadbalancer/LoadBalancer.php - About 1 hr to fix

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

                                    private function closeConnection( IDatabase $conn ) {
                                        if ( $conn instanceof DBConnRef ) {
                                            // Avoid calling close() but still leaving the handle in the pool
                                            throw new RuntimeException( 'Cannot close DBConnRef instance; it must be shareable' );
                                        }
                                Severity: Minor
                                Found in includes/libs/rdbms/loadbalancer/LoadBalancer.php - About 1 hr to fix

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

                                      public function waitForAll( DBPrimaryPos $pos, $timeout = null ) {
                                          $timeout = $timeout ?: self::MAX_WAIT_DEFAULT;
                                  
                                          $oldPos = $this->waitForPos;
                                          try {
                                  Severity: Minor
                                  Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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 flushReplicaSnapshots has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      public function flushReplicaSnapshots( $fname = __METHOD__ ) {
                                          foreach ( $this->conns as $poolConnsByServer ) {
                                              foreach ( $poolConnsByServer as $serverIndex => $serverConns ) {
                                                  if ( $serverIndex === ServerInfo::WRITER_INDEX ) {
                                                      continue; // skip primary
                                  Severity: Minor
                                  Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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 reconfigure has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                      public function reconfigure( array $params ) {
                                          $anyServerDepooled = false;
                                  
                                          $paramServers = $params['servers'];
                                          $newIndexByServerIndex = $this->serverInfo->reconfigureServers( $paramServers );
                                  Severity: Minor
                                  Found in includes/libs/rdbms/loadbalancer/LoadBalancer.php - About 1 hr to fix

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

                                        public function commitPrimaryChanges( $fname = __METHOD__ ) {
                                            $this->assertTransactionRoundStage( self::ROUND_APPROVED );
                                            /** @noinspection PhpUnusedLocalVariableInspection */
                                            $scope = ScopedCallback::newScopedIgnoreUserAbort();
                                    
                                    
                                    Severity: Minor
                                    Found in includes/libs/rdbms/loadbalancer/LoadBalancer.php - About 1 hr to fix

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

                                          private function getRandomNonLagged( array $loads, $maxLag = INF ) {
                                              $lags = $this->getLagTimes();
                                      
                                              # Unset excessively lagged servers
                                              foreach ( $lags as $i => $lag ) {
                                      Severity: Minor
                                      Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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 loadSessionPrimaryPos has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                      Open

                                          private function loadSessionPrimaryPos() {
                                              if ( !$this->chronologyProtectorCalled && $this->chronologyProtector ) {
                                                  $this->chronologyProtectorCalled = true;
                                                  $pos = $this->chronologyProtector->getSessionPrimaryPos( $this );
                                                  $this->logger->debug( __METHOD__ . ': executed chronology callback.' );
                                      Severity: Minor
                                      Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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 getAnyOpenConnection has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                      Open

                                          public function getAnyOpenConnection( $i, $flags = 0 ) {
                                              $i = ( $i === self::DB_PRIMARY ) ? ServerInfo::WRITER_INDEX : $i;
                                              $conn = false;
                                              foreach ( $this->conns as $type => $poolConnsByServer ) {
                                                  if ( $i === self::DB_REPLICA ) {
                                      Severity: Minor
                                      Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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 getServerConnection has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                      Open

                                          public function getServerConnection( $i, $domain, $flags = 0 ) {
                                              $domainInstance = DatabaseDomain::newFromId( $domain );
                                              // Number of connections made before getting the server index and handle
                                              $priorConnectionsMade = $this->connectionCounter;
                                              // Get an open connection to this server (might trigger a new connection)
                                      Severity: Minor
                                      Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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 getConnectionInternal has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                      Open

                                          public function getConnectionInternal( $i, $groups = [], $domain = false, $flags = 0 ): IDatabase {
                                              $domain = $this->resolveDomainID( $domain );
                                              $group = $this->resolveGroups( $groups, $i );
                                              $flags = $this->sanitizeConnectionFlags( $flags, $i, $domain );
                                              // If given DB_PRIMARY/DB_REPLICA, resolve it to a specific server index. Resolving
                                      Severity: Minor
                                      Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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 commitPrimaryChanges has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                      Open

                                          public function commitPrimaryChanges( $fname = __METHOD__ ) {
                                              $this->assertTransactionRoundStage( self::ROUND_APPROVED );
                                              /** @noinspection PhpUnusedLocalVariableInspection */
                                              $scope = ScopedCallback::newScopedIgnoreUserAbort();
                                      
                                      
                                      Severity: Minor
                                      Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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 getMaxLag has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                      Open

                                          public function getMaxLag() {
                                              $host = '';
                                              $maxLag = -1;
                                              $maxIndex = 0;
                                      
                                      
                                      Severity: Minor
                                      Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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 pickAnyOpenConnection has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                      Open

                                          private function pickAnyOpenConnection( array $connsByServer ) {
                                              foreach ( $connsByServer as $i => $conns ) {
                                                  foreach ( $conns as $conn ) {
                                                      if ( !$conn->isOpen() ) {
                                                          $this->logger->warning(
                                      Severity: Minor
                                      Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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 $i;
                                      Severity: Major
                                      Found in includes/libs/rdbms/loadbalancer/LoadBalancer.php - About 30 mins to fix

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

                                            private function reportConnectionError( $extraLbError = '' ) {
                                                if ( $this->lastErrorConn instanceof IDatabase ) {
                                                    $srvName = $this->lastErrorConn->getServerName();
                                                    $lastDbError = $this->lastErrorConn->lastError() ?: 'unknown error';
                                        
                                        
                                        Severity: Minor
                                        Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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

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

                                            private function closeConnection( IDatabase $conn ) {
                                                if ( $conn instanceof DBConnRef ) {
                                                    // Avoid calling close() but still leaving the handle in the pool
                                                    throw new RuntimeException( 'Cannot close DBConnRef instance; it must be shareable' );
                                                }
                                        Severity: Minor
                                        Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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

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

                                            private function sanitizeConnectionFlags( $flags, $i, $domain ) {
                                                // Whether an outside caller is explicitly requesting the primary database server
                                                if ( $i === self::DB_PRIMARY || $i === ServerInfo::WRITER_INDEX ) {
                                                    $flags |= self::CONN_INTENT_WRITABLE;
                                                }
                                        Severity: Minor
                                        Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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

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

                                            private function getOpenConnections() {
                                                foreach ( $this->conns as $poolConnsByServer ) {
                                                    foreach ( $poolConnsByServer as $serverConns ) {
                                                        foreach ( $serverConns as $conn ) {
                                                            yield $conn;
                                        Severity: Minor
                                        Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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

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

                                            public function getReaderIndex( $group = false ) {
                                                $group = is_string( $group ) ? $group : self::GROUP_GENERIC;
                                        
                                                if ( !$this->serverInfo->hasReplicaServers() ) {
                                                    // There is only one possible server to use (the primary)
                                        Severity: Minor
                                        Found in includes/libs/rdbms/loadbalancer/LoadBalancer.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

                                        Similar blocks of code found in 2 locations. Consider refactoring.
                                        Open

                                            final protected function resolveDomainInstance( $domain ): DatabaseDomain {
                                                if ( $domain instanceof DatabaseDomain ) {
                                                    return $domain; // already a domain instance
                                                } elseif ( $domain === false || $domain === $this->localDomain->getId() ) {
                                                    return $this->localDomain;
                                        Severity: Major
                                        Found in includes/libs/rdbms/loadbalancer/LoadBalancer.php and 1 other location - About 3 hrs to fix
                                        includes/libs/rdbms/lbfactory/LBFactoryMulti.php on lines 198..219

                                        Duplicated Code

                                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                        Tuning

                                        This issue has a mass of 155.

                                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                        Refactorings

                                        Further Reading

                                        Similar blocks of code found in 2 locations. Consider refactoring.
                                        Open

                                            public function getConnectionRef( $i, $groups = [], $domain = false, $flags = 0 ): IDatabase {
                                                if ( self::fieldHasBit( $flags, self::CONN_SILENCE_ERRORS ) ) {
                                                    throw new UnexpectedValueException(
                                                        __METHOD__ . ' got CONN_SILENCE_ERRORS; connection is already deferred'
                                                    );
                                        Severity: Major
                                        Found in includes/libs/rdbms/loadbalancer/LoadBalancer.php and 1 other location - About 3 hrs to fix
                                        includes/libs/rdbms/loadbalancer/LoadBalancer.php on lines 842..860

                                        Duplicated Code

                                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                        Tuning

                                        This issue has a mass of 149.

                                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                        Refactorings

                                        Further Reading

                                        Similar blocks of code found in 2 locations. Consider refactoring.
                                        Open

                                            public function getMaintenanceConnectionRef(
                                                $i,
                                                $groups = [],
                                                $domain = false,
                                                $flags = 0
                                        Severity: Major
                                        Found in includes/libs/rdbms/loadbalancer/LoadBalancer.php and 1 other location - About 3 hrs to fix
                                        includes/libs/rdbms/loadbalancer/LoadBalancer.php on lines 827..840

                                        Duplicated Code

                                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                        Tuning

                                        This issue has a mass of 149.

                                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                        Refactorings

                                        Further Reading

                                        There are no issues that match your filters.

                                        Category
                                        Status