Skip to content

Commit

Permalink
Merge "Add static type hints in Wikibase\Lib\Rdbms"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Dec 11, 2024
2 parents 723c9eb + bb3b146 commit 1469e41
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 66 deletions.
7 changes: 2 additions & 5 deletions lib/includes/Rdbms/ClientDomainDbFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@
*/
class ClientDomainDbFactory {

/**
* @var ILBFactory
*/
private $lbFactory;
private ILBFactory $lbFactory;

/**
* @var string[]
*/
private $loadGroups;
private array $loadGroups;

public function __construct( ILBFactory $lbFactory, array $loadGroups = [] ) {
$this->lbFactory = $lbFactory;
Expand Down
32 changes: 7 additions & 25 deletions lib/includes/Rdbms/DomainDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,17 @@ abstract class DomainDb {
public const LOAD_GROUP_FROM_CLIENT = 'from-client';
public const LOAD_GROUP_FROM_REPO = 'from-repo';

/**
* @var ILBFactory
*/
private $lbFactory;

/**
* @var string
*/
private $domainId;

/**
* @var ReplicationWaiter
*/
private $replicationWaiter;
private ILBFactory $lbFactory;
private string $domainId;
private ReplicationWaiter $replicationWaiter;

/**
* @var string[]
*/
private $loadGroups;
private array $loadGroups;

/**
* @var ?SessionConsistentConnectionManager
*/
private $sessionConsistentConnectionManager = null;

/**
* @var ?ConnectionManager
*/
private $connectionManager = null;
private ?SessionConsistentConnectionManager $sessionConsistentConnectionManager = null;
private ?ConnectionManager $connectionManager = null;

public function __construct( ILBFactory $lbFactory, string $domainId, array $loadGroups = [] ) {
$this->lbFactory = $lbFactory;
Expand Down Expand Up @@ -83,7 +65,7 @@ public function sessionConsistentConnections(): SessionConsistentConnectionManag

/**
* WARNING: Do _not_ override the load-groups in individual method calls on ConnectionManager!
* Instead add them to the factory method!
* Instead, add them to the factory method!
*/
public function connections(): ConnectionManager {
if ( $this->connectionManager === null ) {
Expand Down
11 changes: 2 additions & 9 deletions lib/includes/Rdbms/ReplicationWaiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,8 @@
*/
class ReplicationWaiter {

/**
* @var ILBFactory
*/
private $lbFactory;

/**
* @var string
*/
private $domainId;
private ILBFactory $lbFactory;
private string $domainId;

public function __construct(
ILBFactory $lbFactory,
Expand Down
18 changes: 4 additions & 14 deletions lib/includes/Rdbms/RepoDomainDbFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,26 @@
namespace Wikibase\Lib\Rdbms;

use Wikibase\DataAccess\DatabaseEntitySource;
use Wikimedia\Assert\Assert;
use Wikimedia\Rdbms\ILBFactory;

/**
* @license GPL-2.0-or-later
*/
class RepoDomainDbFactory {

/**
* @var string
*/
private $repoDomain;

/**
* @var ILBFactory
*/
private $lbFactory;
private string $repoDomain;
private ILBFactory $lbFactory;

/**
* @var string[]
*/
private $loadGroups;
private array $loadGroups;

public function __construct(
ILBFactory $lbFactory,
$repoDomain,
string $repoDomain,
array $loadGroups = []
) {
// Make sure callers are not passing `false`. Can be replaced with a typehint once all callers have strict_types enabled.
Assert::parameterType( 'string', $repoDomain, '$repoDomain' );
$this->lbFactory = $lbFactory;
$this->repoDomain = $repoDomain;
$this->loadGroups = $loadGroups;
Expand Down
14 changes: 1 addition & 13 deletions lib/tests/phpunit/Rdbms/RepoDomainDbFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Wikibase\DataAccess\DatabaseEntitySource;
use Wikibase\Lib\Rdbms\DomainDb;
use Wikibase\Lib\Rdbms\RepoDomainDbFactory;
use Wikimedia\Assert\ParameterTypeException;
use Wikimedia\Rdbms\ILBFactory;

/**
Expand All @@ -25,10 +24,7 @@ class RepoDomainDbFactoryTest extends \PHPUnit\Framework\TestCase {
*/
private $lbFactory;

/**
* @var string
*/
private $repoDomainId;
private string $repoDomainId;

protected function setUp(): void {
parent::setUp();
Expand Down Expand Up @@ -65,14 +61,6 @@ public function testNewForEntitySource() {
$this->assertSame( $expectedDbName, $db->domain() );
}

public function testDomainMustNotBeEmpty() {
$this->repoDomainId = false;

$this->expectException( ParameterTypeException::class );

$this->newFactory();
}

private function newFactory() {
return new RepoDomainDbFactory(
$this->lbFactory,
Expand Down

0 comments on commit 1469e41

Please sign in to comment.