From: umherirrender Date: Wed, 18 Nov 2015 18:32:05 +0000 (+0100) Subject: phpcs: Assignment expression not allowed X-Git-Tag: 1.31.0-rc.0~8946^2 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=5311afb6a4e37d92878a06edc8b15494b3897a37;p=lhc%2Fweb%2Fwiklou.git phpcs: Assignment expression not allowed Fix some "Assignment expression not allowed" Found by tests: https://integration.wikimedia.org/ci/job/mediawiki-core-phpcs/2736/consoleFull Change-Id: Ibfc62b0aaa5c7fa63081edea3ef2b4d0dc984f85 --- diff --git a/includes/db/DatabaseMysqlBase.php b/includes/db/DatabaseMysqlBase.php index 38aae58645..a839314e1d 100644 --- a/includes/db/DatabaseMysqlBase.php +++ b/includes/db/DatabaseMysqlBase.php @@ -722,10 +722,13 @@ abstract class DatabaseMysqlBase extends Database { $res = $this->doQuery( $sql ); $status = false; - if ( $res && $row = $this->fetchRow( $res ) ) { - $status = $row[0]; // can be NULL, -1, or 0+ per the MySQL manual - if ( ctype_digit( $status ) ) { // success - $this->lastKnownSlavePos = $pos; + if ( $res ) { + $row = $this->fetchRow( $res ); + if ( $row ) { + $status = $row[0]; // can be NULL, -1, or 0+ per the MySQL manual + if ( ctype_digit( $status ) ) { // success + $this->lastKnownSlavePos = $pos; + } } } diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index 66004ec578..a3d7c1b9e1 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -395,7 +395,8 @@ class DatabaseOracle extends Database { MediaWiki\suppressWarnings(); - if ( ( $this->mLastResult = $stmt = oci_parse( $this->mConn, $sql ) ) === false ) { + $this->mLastResult = $stmt = oci_parse( $this->mConn, $sql ); + if ( $stmt === false ) { $e = oci_error( $this->mConn ); $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ ); @@ -637,7 +638,8 @@ class DatabaseOracle extends Database { } $sql .= ')'; - if ( ( $this->mLastResult = $stmt = oci_parse( $this->mConn, $sql ) ) === false ) { + $this->mLastResult = $stmt = oci_parse( $this->mConn, $sql ); + if ( $stmt === false ) { $e = oci_error( $this->mConn ); $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ ); @@ -668,7 +670,8 @@ class DatabaseOracle extends Database { } } else { /** @var OCI_Lob[] $lob */ - if ( ( $lob[$col] = oci_new_descriptor( $this->mConn, OCI_D_LOB ) ) === false ) { + $lob[$col] = oci_new_descriptor( $this->mConn, OCI_D_LOB ); + if ( $lob[$col] === false ) { $e = oci_error( $stmt ); throw new DBUnexpectedError( $this, "Cannot create LOB descriptor: " . $e['message'] ); } @@ -731,7 +734,8 @@ class DatabaseOracle extends Database { $srcTable = $this->tableName( $srcTable ); } - if ( ( $sequenceData = $this->getSequenceData( $destTable ) ) !== false && + $sequenceData = $this->getSequenceData( $destTable ); + if ( $sequenceData !== false && !isset( $varMap[$sequenceData['column']] ) ) { $varMap[$sequenceData['column']] = 'GET_SEQUENCE_VALUE(\'' . $sequenceData['sequence'] . '\')'; @@ -987,7 +991,8 @@ class DatabaseOracle extends Database { 'SELECT version FROM product_component_version ' . 'WHERE UPPER(product) LIKE \'ORACLE DATABASE%\'' ); - if ( !( $row = $rset->fetchRow() ) ) { + $row = $rset->fetchRow(); + if ( !$row ) { return oci_server_version( $this->mConn ); } @@ -1428,7 +1433,8 @@ class DatabaseOracle extends Database { $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND ); } - if ( ( $this->mLastResult = $stmt = oci_parse( $this->mConn, $sql ) ) === false ) { + $this->mLastResult = $stmt = oci_parse( $this->mConn, $sql ); + if ( $stmt === false ) { $e = oci_error( $this->mConn ); $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ ); @@ -1458,7 +1464,8 @@ class DatabaseOracle extends Database { } } else { /** @var OCI_Lob[] $lob */ - if ( ( $lob[$col] = oci_new_descriptor( $this->mConn, OCI_D_LOB ) ) === false ) { + $lob[$col] = oci_new_descriptor( $this->mConn, OCI_D_LOB ); + if ( $lob[$col] === false ) { $e = oci_error( $stmt ); throw new DBUnexpectedError( $this, "Cannot create LOB descriptor: " . $e['message'] ); } diff --git a/includes/db/loadbalancer/LoadMonitorMySQL.php b/includes/db/loadbalancer/LoadMonitorMySQL.php index 39077c200e..31f616366e 100644 --- a/includes/db/loadbalancer/LoadMonitorMySQL.php +++ b/includes/db/loadbalancer/LoadMonitorMySQL.php @@ -90,9 +90,15 @@ class LoadMonitorMySQL implements LoadMonitor { foreach ( $serverIndexes as $i ) { if ( $i == 0 ) { # Master $lagTimes[$i] = 0; - } elseif ( false !== ( $conn = $this->parent->getAnyOpenConnection( $i ) ) ) { + continue; + } + $conn = $this->parent->getAnyOpenConnection( $i ); + if ( $conn !== false ) { $lagTimes[$i] = $conn->getLag(); - } elseif ( false !== ( $conn = $this->parent->openConnection( $i, $wiki ) ) ) { + continue; + } + $conn = $this->parent->openConnection( $i, $wiki ); + if ( $conn !== false ) { $lagTimes[$i] = $conn->getLag(); # Close the connection to avoid sleeper connections piling up. # Note that the caller will pick one of these DBs and reconnect, diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index ee11df953e..72f12d19f2 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -1176,8 +1176,13 @@ abstract class File implements IDBAccessObject { if ( !$this->repo || !isset( $params['physicalWidth'] ) || !isset( $params['physicalHeight'] ) - || !( $bucket = $this->getThumbnailBucket( $params['physicalWidth'] ) ) - || $bucket == $params['physicalWidth'] ) { + ) { + return false; + } + + $bucket = $this->getThumbnailBucket( $params['physicalWidth'] ); + + if ( !$bucket || $bucket == $params['physicalWidth'] ) { return false; } diff --git a/includes/gallery/TraditionalImageGallery.php b/includes/gallery/TraditionalImageGallery.php index 181c7b8e08..d2f7417351 100644 --- a/includes/gallery/TraditionalImageGallery.php +++ b/includes/gallery/TraditionalImageGallery.php @@ -111,48 +111,51 @@ class TraditionalImageGallery extends ImageGalleryBase { htmlspecialchars( $nt->getText() ) ) . ''; - } elseif ( !( $thumb = $img->transform( $transformOptions ) ) ) { - # Error generating thumbnail. - $thumbhtml = "\n\t\t\t" . '
' - . htmlspecialchars( $img->getLastError() ) . '
'; } else { - /** @var MediaTransformOutput $thumb */ - $vpad = $this->getVPad( $this->mHeights, $thumb->getHeight() ); - - $imageParameters = array( - 'desc-link' => true, - 'desc-query' => $descQuery, - 'alt' => $alt, - 'custom-url-link' => $link - ); - - // In the absence of both alt text and caption, fall back on - // providing screen readers with the filename as alt text - if ( $alt == '' && $text == '' ) { - $imageParameters['alt'] = $nt->getText(); - } - - $this->adjustImageParameters( $thumb, $imageParameters ); - - Linker::processResponsiveImages( $img, $thumb, $transformOptions ); - - # Set both fixed width and min-height. - $thumbhtml = "\n\t\t\t" - . '
' - # Auto-margin centering for block-level elements. Needed - # now that we have video handlers since they may emit block- - # level elements as opposed to simple tags. ref - # http://css-discuss.incutio.com/?page=CenteringBlockElement - . '
' - . $thumb->toHtml( $imageParameters ) . '
'; - - // Call parser transform hook - /** @var MediaHandler $handler */ - $handler = $img->getHandler(); - if ( $this->mParser && $handler ) { - $handler->parserTransformHook( $this->mParser, $img ); + $thumb = $img->transform( $transformOptions ); + if ( !$thumb ) { + # Error generating thumbnail. + $thumbhtml = "\n\t\t\t" . '
' + . htmlspecialchars( $img->getLastError() ) . '
'; + } else { + /** @var MediaTransformOutput $thumb */ + $vpad = $this->getVPad( $this->mHeights, $thumb->getHeight() ); + + $imageParameters = array( + 'desc-link' => true, + 'desc-query' => $descQuery, + 'alt' => $alt, + 'custom-url-link' => $link + ); + + // In the absence of both alt text and caption, fall back on + // providing screen readers with the filename as alt text + if ( $alt == '' && $text == '' ) { + $imageParameters['alt'] = $nt->getText(); + } + + $this->adjustImageParameters( $thumb, $imageParameters ); + + Linker::processResponsiveImages( $img, $thumb, $transformOptions ); + + # Set both fixed width and min-height. + $thumbhtml = "\n\t\t\t" + . '
' + # Auto-margin centering for block-level elements. Needed + # now that we have video handlers since they may emit block- + # level elements as opposed to simple tags. ref + # http://css-discuss.incutio.com/?page=CenteringBlockElement + . '
' + . $thumb->toHtml( $imageParameters ) . '
'; + + // Call parser transform hook + /** @var MediaHandler $handler */ + $handler = $img->getHandler(); + if ( $this->mParser && $handler ) { + $handler->parserTransformHook( $this->mParser, $img ); + } } } diff --git a/includes/installer/PostgresUpdater.php b/includes/installer/PostgresUpdater.php index 7414d926c7..87e6566fd7 100644 --- a/includes/installer/PostgresUpdater.php +++ b/includes/installer/PostgresUpdater.php @@ -512,7 +512,8 @@ END; if ( !$res ) { return null; } - if ( !( $r = $this->db->fetchRow( $res ) ) ) { + $r = $this->db->fetchRow( $res ); + if ( !$r ) { return null; } @@ -532,7 +533,8 @@ END; if ( !$r2 ) { return null; } - if ( !( $row2 = $this->db->fetchRow( $r2 ) ) ) { + $row2 = $this->db->fetchRow( $r2 ); + if ( !$row2 ) { return null; } $colnames[] = $row2[0]; @@ -555,7 +557,8 @@ END; $this->db->addQuotes( $fkey ) ) ); - if ( !( $row = $this->db->fetchRow( $r ) ) ) { + $row = $this->db->fetchRow( $r ); + if ( !$row ) { return null; } diff --git a/includes/parser/LinkHolderArray.php b/includes/parser/LinkHolderArray.php index 41b5decbed..6329fd7a1f 100644 --- a/includes/parser/LinkHolderArray.php +++ b/includes/parser/LinkHolderArray.php @@ -315,15 +315,18 @@ class LinkHolderArray { $colours[$pdbk] = ''; } elseif ( $ns == NS_SPECIAL ) { $colours[$pdbk] = 'new'; - } elseif ( ( $id = $linkCache->getGoodLinkID( $pdbk ) ) != 0 ) { - $colours[$pdbk] = Linker::getLinkColour( $title, $threshold ); - $output->addLink( $title, $id ); - $linkcolour_ids[$id] = $pdbk; - } elseif ( $linkCache->isBadLink( $pdbk ) ) { - $colours[$pdbk] = 'new'; } else { - # Not in the link cache, add it to the query - $queries[$ns][] = $title->getDBkey(); + $id = $linkCache->getGoodLinkID( $pdbk ); + if ( $id != 0 ) { + $colours[$pdbk] = Linker::getLinkColour( $title, $threshold ); + $output->addLink( $title, $id ); + $linkcolour_ids[$id] = $pdbk; + } elseif ( $linkCache->isBadLink( $pdbk ) ) { + $colours[$pdbk] = 'new'; + } else { + # Not in the link cache, add it to the query + $queries[$ns][] = $title->getDBkey(); + } } } } diff --git a/tests/phpunit/includes/db/DatabaseSqliteTest.php b/tests/phpunit/includes/db/DatabaseSqliteTest.php index 0db7af9392..c742f745e1 100644 --- a/tests/phpunit/includes/db/DatabaseSqliteTest.php +++ b/tests/phpunit/includes/db/DatabaseSqliteTest.php @@ -100,7 +100,8 @@ class DatabaseSqliteTest extends MediaWikiTestCase { $this->assertTrue( $re !== false, 'query failed' ); - if ( $row = $re->fetchRow() ) { + $row = $re->fetchRow(); + if ( $row ) { if ( $value instanceof Blob ) { $value = $value->fetch(); } diff --git a/tests/phpunit/includes/parser/NewParserTest.php b/tests/phpunit/includes/parser/NewParserTest.php index ff4a5271f2..f7c428a66d 100644 --- a/tests/phpunit/includes/parser/NewParserTest.php +++ b/tests/phpunit/includes/parser/NewParserTest.php @@ -640,11 +640,12 @@ class NewParserTest extends MediaWikiTestCase { $backend->delete( array( 'src' => $file ), array( 'force' => 1 ) ); } foreach ( $files as $file ) { - $tmp = $file; - while ( $tmp = FileBackend::parentStoragePath( $tmp ) ) { + $tmp = FileBackend::parentStoragePath( $file ); + while ( $tmp ) { if ( !$backend->clean( array( 'dir' => $tmp ) )->isOK() ) { break; } + $tmp = FileBackend::parentStoragePath( $tmp ); } } }