This was originally a global search and replace. I manually checked all
replacements and reverted them if (due to the lack of type hints) either
null (that would be 0 when counted) or a Countable object can end in the
variable or property in question.
Now this patch only touches places where I'm sure nothing can break.
For the sanity of the honorable reviewers this patch is exclusively touching
negated counts. You should not find a single `!== []` in this patch, that
would be a mistake.
Change-Id: I5eafd4d8fccdb53a668be8e6f25a566f9c3a0a95
40 files changed:
* @since 1.22
*/
public static function getBlocksForIPList( array $ipChain, $isAnon, $fromMaster = false ) {
* @since 1.22
*/
public static function getBlocksForIPList( array $ipChain, $isAnon, $fromMaster = false ) {
- if ( !count( $ipChain ) ) {
+ if ( $ipChain === [] ) {
$conds[] = self::getRangeCond( IP::toHex( $ipaddr ) );
}
$conds[] = self::getRangeCond( IP::toHex( $ipaddr ) );
}
- if ( !count( $conds ) ) {
* @return Block|null The "best" block from the list
*/
public static function chooseBlock( array $blocks, array $ipChain ) {
* @return Block|null The "best" block from the list
*/
public static function chooseBlock( array $blocks, array $ipChain ) {
- if ( !count( $blocks ) ) {
+ if ( $blocks === [] ) {
return null;
} elseif ( count( $blocks ) == 1 ) {
return $blocks[0];
return null;
} elseif ( count( $blocks ) == 1 ) {
return $blocks[0];
// Already compressed
return;
}
// Already compressed
return;
}
- if ( !count( $this->mItems ) ) {
- // Empty
+ if ( $this->mItems === [] ) {
$this->mDiffs = [];
$this->mDiffMap = [];
foreach ( $sequences as $seq ) {
$this->mDiffs = [];
$this->mDiffMap = [];
foreach ( $sequences as $seq ) {
- if ( !count( $seq['diffs'] ) ) {
+ if ( $seq['diffs'] === [] ) {
continue;
}
if ( $tail === '' ) {
continue;
}
if ( $tail === '' ) {
*/
function __sleep() {
$this->compress();
*/
function __sleep() {
$this->compress();
- if ( !count( $this->mItems ) ) {
- // Empty object
+ if ( $this->mItems === [] ) {
$info = false;
} else {
// Take forward differences to improve the compression ratio for sequences
$info = false;
} else {
// Take forward differences to improve the compression ratio for sequences
}
// no group with the given right(s) exists, no need for a query
}
// no group with the given right(s) exists, no need for a query
- if ( !count( $groups ) ) {
+ if ( $groups === [] ) {
$this->getResult()->addIndexedTagName( [ 'query', $this->getModuleName() ], '' );
return;
$this->getResult()->addIndexedTagName( [ 'query', $this->getModuleName() ], '' );
return;
if ( count( $ids ) ) {
$ids = $this->filterIDs( [ [ $table, $field ] ], $ids );
if ( count( $ids ) ) {
$ids = $this->filterIDs( [ [ $table, $field ] ], $ids );
- if ( !count( $ids ) ) {
// Return nothing, no IDs are valid
$this->where[] = '0 = 1';
} else {
// Return nothing, no IDs are valid
$this->where[] = '0 = 1';
} else {
return $v >= $cont_page;
} );
}
return $v >= $cont_page;
} );
}
- if ( !count( $pages ) ) {
// Nothing to do
return;
}
// Nothing to do
return;
}
$getTitles[] = $t->getTalkPage();
}
}
$getTitles[] = $t->getTalkPage();
}
}
- if ( !count( $getTitles ) ) {
+ if ( $getTitles === [] ) {
$pageIds = array_keys( $this->titles );
$pageIds = array_keys( $this->titles );
- if ( !count( $pageIds ) ) {
+ if ( $pageIds === [] ) {
}
private function getVariantTitles() {
}
private function getVariantTitles() {
- if ( !count( $this->titles ) ) {
+ if ( $this->titles === [] ) {
return;
}
$this->variantTitles = [];
return;
}
$this->variantTitles = [];
$pages = $filteredPages;
}
$pages = $filteredPages;
}
- if ( !count( $pages ) ) {
# Nothing to do
return;
}
# Nothing to do
return;
}
// prepareQuery might try to sort by actor and confuse everything.
$batchSize = 1;
} elseif ( isset( $this->params['userids'] ) ) {
// prepareQuery might try to sort by actor and confuse everything.
$batchSize = 1;
} elseif ( isset( $this->params['userids'] ) ) {
- if ( !count( $this->params['userids'] ) ) {
+ if ( $this->params['userids'] === [] ) {
$encParamName = $this->encodeParamName( 'userids' );
$this->dieWithError( [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName" );
}
$encParamName = $this->encodeParamName( 'userids' );
$this->dieWithError( [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName" );
}
$writeSockets["$clientIndex/$i"] = $socket;
}
}
$writeSockets["$clientIndex/$i"] = $socket;
}
}
- if ( !count( $readSockets ) && !count( $writeSockets ) ) {
+ if ( $readSockets === [] && $writeSockets === [] ) {
$exceptSockets = null;
$timeout = min( $startTime + $this->timeout - microtime( true ), 1 );
Wikimedia\suppressWarnings();
$exceptSockets = null;
$timeout = min( $startTime + $this->timeout - microtime( true ), 1 );
Wikimedia\suppressWarnings();
public function upsert( $table, array $rows, array $uniqueIndexes, array $set,
$fname = __METHOD__
) {
public function upsert( $table, array $rows, array $uniqueIndexes, array $set,
$fname = __METHOD__
) {
- if ( !count( $rows ) ) {
return true; // nothing to do
}
return true; // nothing to do
}
* @return mixed[]
*/
public function mergeClassesIntoAttributes( array $classes, array $attribs ) {
* @return mixed[]
*/
public function mergeClassesIntoAttributes( array $classes, array $attribs ) {
- if ( !count( $classes ) ) {
+ if ( $classes === [] ) {
* @return array[] An Array of arrays or iterators of file objects and the hash as key
*/
function findBySha1s( array $hashes ) {
* @return array[] An Array of arrays or iterators of file objects and the hash as key
*/
function findBySha1s( array $hashes ) {
- if ( !count( $hashes ) ) {
+ if ( $hashes === [] ) {
return []; // empty parameter
}
return []; // empty parameter
}
$conds['fa_sha1'] = $this->sha1;
}
$conds['fa_sha1'] = $this->sha1;
}
- if ( !count( $conds ) ) {
throw new MWException( "No specific information for retrieving archived file" );
}
throw new MWException( "No specific information for retrieving archived file" );
}
final public function batchPush( array $jobs, $flags = 0 ) {
$this->assertNotReadOnly();
final public function batchPush( array $jobs, $flags = 0 ) {
$this->assertNotReadOnly();
- if ( !count( $jobs ) ) {
return; // nothing to do
}
return; // nothing to do
}
* @return void
*/
public function doBatchPushInternal( IDatabase $dbw, array $jobs, $flags, $method ) {
* @return void
*/
public function doBatchPushInternal( IDatabase $dbw, array $jobs, $flags, $method ) {
- if ( !count( $jobs ) ) {
}
$jobs = is_array( $jobs ) ? $jobs : [ $jobs ];
}
$jobs = is_array( $jobs ) ? $jobs : [ $jobs ];
- if ( !count( $jobs ) ) {
- if ( !count( $items ) ) {
return; // nothing to do
}
return; // nothing to do
}
if ( empty( $opts['bypassReadOnly'] ) && $this->isReadOnly() ) {
return $this->newStatus( 'backend-fail-readonly', $this->name, $this->readOnly );
}
if ( empty( $opts['bypassReadOnly'] ) && $this->isReadOnly() ) {
return $this->newStatus( 'backend-fail-readonly', $this->name, $this->readOnly );
}
- if ( !count( $ops ) ) {
return $this->newStatus(); // nothing to do
}
return $this->newStatus(); // nothing to do
}
if ( empty( $opts['bypassReadOnly'] ) && $this->isReadOnly() ) {
return $this->newStatus( 'backend-fail-readonly', $this->name, $this->readOnly );
}
if ( empty( $opts['bypassReadOnly'] ) && $this->isReadOnly() ) {
return $this->newStatus( 'backend-fail-readonly', $this->name, $this->readOnly );
}
- if ( !count( $ops ) ) {
return $this->newStatus(); // nothing to do
}
return $this->newStatus(); // nothing to do
}
* @return StatusValue
*/
final public function logChangeBatch( array $entries, $batchId ) {
* @return StatusValue
*/
final public function logChangeBatch( array $entries, $batchId ) {
- if ( !count( $entries ) ) {
+ if ( $entries === [] ) {
return StatusValue::newGood();
}
return StatusValue::newGood();
}
if ( $this->locksHeld[$path][$type] <= 0 ) {
unset( $this->locksHeld[$path][$type] );
}
if ( $this->locksHeld[$path][$type] <= 0 ) {
unset( $this->locksHeld[$path][$type] );
}
- if ( !count( $this->locksHeld[$path] ) ) {
+ if ( $this->locksHeld[$path] === [] ) {
unset( $this->locksHeld[$path] ); // no locks on this path
if ( isset( $this->handles[$path] ) ) {
$handlesToClose[] = $this->handles[$path];
unset( $this->locksHeld[$path] ); // no locks on this path
if ( isset( $this->handles[$path] ) ) {
$handlesToClose[] = $this->handles[$path];
protected function doGetLocksOnServer( $lockSrv, array $paths, $type ) {
$status = StatusValue::newGood();
protected function doGetLocksOnServer( $lockSrv, array $paths, $type ) {
$status = StatusValue::newGood();
- if ( !count( $paths ) ) {
return $status; // nothing to lock
}
return $status; // nothing to lock
}
$bucket = $this->getBucketFromPath( $path );
$pathsToUnlock[$bucket][$type][] = $path;
}
$bucket = $this->getBucketFromPath( $path );
$pathsToUnlock[$bucket][$type][] = $path;
}
- if ( !count( $this->locksHeld[$path] ) ) {
+ if ( $this->locksHeld[$path] === [] ) {
unset( $this->locksHeld[$path] ); // no SH or EX locks left for key
}
}
unset( $this->locksHeld[$path] ); // no SH or EX locks left for key
}
}
foreach ( $pathsToUnlock as $bucket => $pathsToUnlockByType ) {
$status->merge( $this->doUnlockingRequestBucket( $bucket, $pathsToUnlockByType ) );
}
foreach ( $pathsToUnlock as $bucket => $pathsToUnlockByType ) {
$status->merge( $this->doUnlockingRequestBucket( $bucket, $pathsToUnlockByType ) );
}
- if ( !count( $this->locksHeld ) ) {
+ if ( $this->locksHeld === [] ) {
$status->merge( $this->releaseAllLocks() );
$this->degradedBuckets = []; // safe to retry the normal quorum
}
$status->merge( $this->releaseAllLocks() );
$this->degradedBuckets = []; // safe to retry the normal quorum
}
- if ( !count( $this->shutdownPositions ) ) {
+ if ( $this->shutdownPositions === [] ) {
return []; // nothing to save
}
return []; // nothing to save
}
public function upsert( $table, array $rows, array $uniqueIndexes, array $set,
$fname = __METHOD__
) {
public function upsert( $table, array $rows, array $uniqueIndexes, array $set,
$fname = __METHOD__
) {
- if ( !count( $rows ) ) {
return true; // nothing to do
}
return true; // nothing to do
}
public function upsert( $table, array $rows, array $uniqueIndexes,
array $set, $fname = __METHOD__
) {
public function upsert( $table, array $rows, array $uniqueIndexes,
array $set, $fname = __METHOD__
) {
- if ( !count( $rows ) ) {
return true; // nothing to do
}
return true; // nothing to do
}
* @return array (reader index, lagged replica mode) or false on failure
*/
private function pickReaderIndex( array $loads, $domain = false ) {
* @return array (reader index, lagged replica mode) or false on failure
*/
private function pickReaderIndex( array $loads, $domain = false ) {
- if ( !count( $loads ) ) {
throw new InvalidArgumentException( "Empty server array given to LoadBalancer" );
}
throw new InvalidArgumentException( "Empty server array given to LoadBalancer" );
}
}
// If all servers were down, quit now
}
// If all servers were down, quit now
- if ( !count( $currentLoads ) ) {
+ if ( $currentLoads === [] ) {
$this->connLogger->error( __METHOD__ . ": all servers down" );
}
$this->connLogger->error( __METHOD__ . ": all servers down" );
}
// If nobody is watching the page, and there are no users notified on all changes
// don't bother creating a job/trying to send emails, unless it's a
// talk page with an applicable notification.
// If nobody is watching the page, and there are no users notified on all changes
// don't bother creating a job/trying to send emails, unless it's a
// talk page with an applicable notification.
- if ( !count( $watchers ) && !count( $wgUsersNotifiedOnAllChanges ) ) {
+ if ( $watchers === [] && !count( $wgUsersNotifiedOnAllChanges ) ) {
$sendEmail = false;
// Only send notification for non minor edits, unless $wgEnotifMinorEdits
if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) {
$sendEmail = false;
// Only send notification for non minor edits, unless $wgEnotifMinorEdits
if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) {
}
public function pop() {
}
public function pop() {
- if ( !count( $this->stack ) ) {
+ if ( $this->stack === [] ) {
throw new MWException( __METHOD__ . ': no elements remaining' );
}
$temp = array_pop( $this->stack );
throw new MWException( __METHOD__ . ': no elements remaining' );
}
$temp = array_pop( $this->stack );
* @return array
*/
public function getFlags() {
* @return array
*/
public function getFlags() {
- if ( !count( $this->stack ) ) {
+ if ( $this->stack === [] ) {
return [
'findEquals' => false,
'findPipe' => false,
return [
'findEquals' => false,
'findPipe' => false,
}
// Save response to file cache unless there are errors
}
// Save response to file cache unless there are errors
- if ( isset( $fileCache ) && !$this->errors && !count( $missing ) ) {
+ if ( isset( $fileCache ) && !$this->errors && $missing === [] ) {
// Cache single modules and images...and other requests if there are enough hits
if ( ResourceFileCache::useFileCache( $context ) ) {
if ( $fileCache->isCacheWorthy() ) {
// Cache single modules and images...and other requests if there are enough hits
if ( ResourceFileCache::useFileCache( $context ) ) {
if ( $fileCache->isCacheWorthy() ) {
- if ( !count( $modules ) && !count( $missing ) ) {
+ if ( $modules === [] && $missing === [] ) {
return <<<MESSAGE
/* This file is the Web entry point for MediaWiki's ResourceLoader:
<https://www.mediawiki.org/wiki/ResourceLoader>. In this request,
return <<<MESSAGE
/* This file is the Web entry point for MediaWiki's ResourceLoader:
<https://www.mediawiki.org/wiki/ResourceLoader>. In this request,
if ( is_null( $this->namespaces ) ) {
return '';
}
if ( is_null( $this->namespaces ) ) {
return '';
}
- if ( !count( $this->namespaces ) ) {
+ if ( $this->namespaces === [] ) {
$namespaces = '0';
} else {
$namespaces = $this->db->makeList( $this->namespaces );
$namespaces = '0';
} else {
$namespaces = $this->db->makeList( $this->namespaces );
if ( is_null( $this->namespaces ) ) {
return ''; # search all
}
if ( is_null( $this->namespaces ) ) {
return ''; # search all
}
- if ( !count( $this->namespaces ) ) {
+ if ( $this->namespaces === [] ) {
$namespaces = '0';
} else {
$namespaces = $this->db->makeList( $this->namespaces );
$namespaces = '0';
} else {
$namespaces = $this->db->makeList( $this->namespaces );
$out = $this->getOutput();
$allCats = $out->getCategoryLinks();
$out = $this->getOutput();
$allCats = $out->getCategoryLinks();
- if ( !count( $allCats ) ) {
+ if ( $allCats === [] ) {
* Attempts to clean up broken items
*/
private function cleanupWatchlist() {
* Attempts to clean up broken items
*/
private function cleanupWatchlist() {
- if ( !count( $this->badItems ) ) {
+ if ( $this->badItems === [] ) {
return; // nothing to do
}
return; // nothing to do
}
'<span class="mw-listgrants-right-name">' . $permission . '</span>'
)->parse();
}
'<span class="mw-listgrants-right-name">' . $permission . '</span>'
)->parse();
}
- if ( !count( $descs ) ) {
$grantCellHtml = '';
} else {
sort( $descs );
$grantCellHtml = '';
} else {
sort( $descs );
'<span class="mw-passwordpolicies-policy-name">' . $gp . '</span>'
)->parse();
}
'<span class="mw-passwordpolicies-policy-name">' . $gp . '</span>'
)->parse();
}
- if ( !count( $ret ) ) {
return '';
} else {
return '<ul><li>' . implode( "</li>\n<li>", $ret ) . '</li></ul>';
return '';
} else {
return '<ul><li>' . implode( "</li>\n<li>", $ret ) . '</li></ul>';
$categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
$categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
- if ( !count( $categories ) ) {
+ if ( $categories === [] ) {
- if ( !count( $articles ) || !count( $cats ) ) {
+ if ( $articles === [] || $cats === [] ) {
# Extract manually requested namespaces
$nslist = $this->powerSearch( $request );
# Extract manually requested namespaces
$nslist = $this->powerSearch( $request );
- if ( !count( $nslist ) ) {
+ if ( $nslist === [] ) {
# Fallback to user preference
$nslist = $this->searchConfig->userNamespaces( $user );
}
$profile = null;
# Fallback to user preference
$nslist = $this->searchConfig->userNamespaces( $user );
}
$profile = null;
- if ( !count( $nslist ) ) {
+ if ( $nslist === [] ) {
$pages = MediaWikiServices::getInstance()->getSpecialPageFactory()->
getUsablePages( $this->getUser() );
$pages = MediaWikiServices::getInstance()->getSpecialPageFactory()->
getUsablePages( $this->getUser() );
- if ( !count( $pages ) ) {
# Yeah, that was pointless. Thanks for coming.
return false;
}
# Yeah, that was pointless. Thanks for coming.
return false;
}
}
# Extra message, when no category was found
}
# Extra message, when no category was found
- if ( !count( $allMsgs ) ) {
+ if ( $allMsgs === [] ) {
$allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse();
}
$allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse();
}
if ( is_array( $data ) ) {
if ( isset( $data['user_groups'] ) && is_array( $data['user_groups'] ) ) {
if ( is_array( $data ) ) {
if ( isset( $data['user_groups'] ) && is_array( $data['user_groups'] ) ) {
- if ( !count( $data['user_groups'] ) ) {
+ if ( $data['user_groups'] === [] ) {
$this->mGroupMemberships = [];
} else {
$firstGroup = reset( $data['user_groups'] );
$this->mGroupMemberships = [];
} else {
$firstGroup = reset( $data['user_groups'] );
}
$toPromote = Autopromote::getAutopromoteOnceGroups( $this, $event );
}
$toPromote = Autopromote::getAutopromoteOnceGroups( $this, $event );
- if ( !count( $toPromote ) ) {
+ if ( $toPromote === [] ) {