Merge "rdbms: Add some return typehints to SelectQueryBuilder"

This commit is contained in:
jenkins-bot 2024-04-21 09:52:05 +00:00 committed by Gerrit Code Review
commit 401c78b10e
7 changed files with 20 additions and 16 deletions

View file

@ -378,13 +378,13 @@ class DBConnRef implements IMaintainableDatabase {
public function estimateRowCount(
$tables, $vars = '*', $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
) {
): int {
return $this->__call( __FUNCTION__, func_get_args() );
}
public function selectRowCount(
$tables, $vars = '*', $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
) {
): int {
return $this->__call( __FUNCTION__, func_get_args() );
}

View file

@ -1373,7 +1373,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
*/
public function estimateRowCount(
$tables, $var = '*', $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
) {
): int {
$conds = $this->platform->normalizeConditions( $conds, $fname );
$column = $this->platform->extractSingleFieldFromList( $var );
if ( is_string( $column ) && !in_array( $column, [ '*', '1' ] ) ) {
@ -1390,7 +1390,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
public function selectRowCount(
$tables, $var = '*', $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
) {
): int {
$conds = $this->platform->normalizeConditions( $conds, $fname );
$column = $this->platform->extractSingleFieldFromList( $var );
if ( is_string( $column ) && !in_array( $column, [ '*', '1' ] ) ) {

View file

@ -293,7 +293,7 @@ class DatabaseMySQL extends Database {
* @param string $fname
* @param string|array $options
* @param array $join_conds
* @return int|false
* @return int
*/
public function estimateRowCount(
$tables,
@ -302,7 +302,7 @@ class DatabaseMySQL extends Database {
$fname = __METHOD__,
$options = [],
$join_conds = []
) {
): int {
$conds = $this->platform->normalizeConditions( $conds, $fname );
$column = $this->platform->extractSingleFieldFromList( $var );
if ( is_string( $column ) && !in_array( $column, [ '*', '1' ] ) ) {
@ -312,7 +312,7 @@ class DatabaseMySQL extends Database {
$options['EXPLAIN'] = true;
$res = $this->select( $tables, $var, $conds, $fname, $options, $join_conds );
if ( $res === false ) {
return false;
return -1;
}
if ( !$res->numRows() ) {
return 0;

View file

@ -294,7 +294,7 @@ class DatabasePostgres extends Database {
*/
public function estimateRowCount( $table, $var = '*', $conds = '',
$fname = __METHOD__, $options = [], $join_conds = []
) {
): int {
$conds = $this->platform->normalizeConditions( $conds, $fname );
$column = $this->platform->extractSingleFieldFromList( $var );
if ( is_string( $column ) && !in_array( $column, [ '*', '1' ] ) ) {

View file

@ -482,7 +482,7 @@ interface IReadableDatabase extends ISQLPlatform, DbQuoter, IDatabaseFlags {
*/
public function estimateRowCount(
$tables, $var = '*', $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
);
): int;
/**
* Get the number of rows in dataset
@ -515,7 +515,7 @@ interface IReadableDatabase extends ISQLPlatform, DbQuoter, IDatabaseFlags {
*/
public function selectRowCount(
$tables, $var = '*', $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
);
): int;
/**
* Returns true if DBs are assumed to be on potentially different servers

View file

@ -725,7 +725,7 @@ class SelectQueryBuilder extends JoinGroupBase {
* @return IResultWrapper
* @return-taint tainted
*/
public function fetchResultSet() {
public function fetchResultSet(): IResultWrapper {
return $this->db->select( $this->tables, $this->fields, $this->conds, $this->caller,
$this->options, $this->joinConds );
}
@ -735,7 +735,7 @@ class SelectQueryBuilder extends JoinGroupBase {
* from the first result row. This may only be called when only one field
* has been added to the builder.
*
* @return mixed
* @return mixed|false The value from the field, or false if nothing was found
* @return-taint tainted
*/
public function fetchField() {
@ -756,7 +756,7 @@ class SelectQueryBuilder extends JoinGroupBase {
* @return array
* @return-taint tainted
*/
public function fetchFieldValues() {
public function fetchFieldValues(): array {
if ( count( $this->fields ) !== 1 ) {
throw new \UnexpectedValueException(
__METHOD__ . ' expects the query to have only one field' );
@ -790,7 +790,7 @@ class SelectQueryBuilder extends JoinGroupBase {
*
* @return int
*/
public function fetchRowCount() {
public function fetchRowCount(): int {
return $this->db->selectRowCount( $this->tables, $this->getRowCountVar(), $this->conds,
$this->caller, $this->options, $this->joinConds );
}
@ -805,7 +805,7 @@ class SelectQueryBuilder extends JoinGroupBase {
*
* @return int
*/
public function estimateRowCount() {
public function estimateRowCount(): int {
return $this->db->estimateRowCount( $this->tables, $this->getRowCountVar(), $this->conds,
$this->caller, $this->options, $this->joinConds );
}

View file

@ -833,7 +833,7 @@ class WatchedItemStoreUnitTest extends MediaWikiIntegrationTestCase {
],
$this->isType( 'string' )
)
->willReturn( '9' );
->willReturn( 9 );
$mockCache = $this->getMockCache();
$mockCache->expects( $this->never() )->method( 'set' );
@ -1161,6 +1161,7 @@ class WatchedItemStoreUnitTest extends MediaWikiIntegrationTestCase {
$mockCache->expects( $this->once() )
->method( 'delete' )
->with( '0:Some_Page:1' );
$mockDb->method( 'select' )->willReturn( new FakeResultWrapper( [] ) );
$store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
@ -3325,7 +3326,10 @@ class WatchedItemStoreUnitTest extends MediaWikiIntegrationTestCase {
},
]
);
$mockDb = $this->getMockDb();
$mockDb->method( 'select' )->willReturn( new FakeResultWrapper( [] ) );
$store = $this->newWatchedItemStore( [
'db' => $mockDb,
'cache' => $mockCache,
'revisionLookup' => $mockRevisionLookup,
'stash' => $stash,