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
LoadBalancer
has 83 functions (exceeds 20 allowed). Consider refactoring. Open
class LoadBalancer implements ILoadBalancerForOwner {
/** @var ILoadMonitor */
private $loadMonitor;
/** @var BagOStuff */
private $srvCache;
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;
- Read upRead up
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();
}
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();
}
- Read upRead up
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;
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 );
- Read upRead up
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;
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();
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;
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" );
}
- Read upRead up
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();
- Read upRead up
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;
- Read upRead up
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();
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)" );
- Read upRead up
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';
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" );
}
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
}
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
}
- Read upRead up
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;
- Read upRead up
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();
- Read upRead up
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 {
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(
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 ) {
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)
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' );
}
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 {
- Read upRead up
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
- Read upRead up
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 );
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();
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 ) {
- Read upRead up
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.' );
- Read upRead up
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 ) {
- Read upRead up
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)
- Read upRead up
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
- Read upRead up
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();
- Read upRead up
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;
- Read upRead up
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(
- Read upRead up
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;
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';
- Read upRead up
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' );
}
- Read upRead up
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;
}
- Read upRead up
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;
- Read upRead up
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)
- Read upRead up
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;
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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'
);
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
public function getMaintenanceConnectionRef(
$i,
$groups = [],
$domain = false,
$flags = 0
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76