Unverified Commit 9e2a9a40 authored by Jonathan H. Wage's avatar Jonathan H. Wage Committed by Sergei Morozov

Add proper types to the Doctrine\DBAL\Sharding namespace.

parent f90c5001
......@@ -18,7 +18,7 @@ class PoolingShardManager implements ShardManager
/** @var ShardChoser */
private $choser;
/** @var string|null */
/** @var mixed */
private $currentDistributionValue;
public function __construct(PoolingShardConnection $conn)
......@@ -31,7 +31,7 @@ class PoolingShardManager implements ShardManager
/**
* {@inheritDoc}
*/
public function selectGlobal()
public function selectGlobal() : void
{
$this->conn->connect(0);
$this->currentDistributionValue = null;
......@@ -40,7 +40,7 @@ class PoolingShardManager implements ShardManager
/**
* {@inheritDoc}
*/
public function selectShard($distributionValue)
public function selectShard($distributionValue) : void
{
$shardId = $this->choser->pickShard($distributionValue, $this->conn);
$this->conn->connect($shardId);
......@@ -58,7 +58,7 @@ class PoolingShardManager implements ShardManager
/**
* {@inheritDoc}
*/
public function getShards()
public function getShards() : array
{
$params = $this->conn->getParams();
$shards = [];
......@@ -75,7 +75,7 @@ class PoolingShardManager implements ShardManager
*
* @throws RuntimeException
*/
public function queryAll($sql, array $params, array $types)
public function queryAll(string $sql, array $params, array $types) : array
{
$shards = $this->getShards();
if (! $shards) {
......
......@@ -158,7 +158,7 @@ class SQLAzureFederationsSynchronizer extends AbstractSchemaSynchronizer
/**
* @return Schema[]
*/
private function partitionSchema(Schema $schema)
private function partitionSchema(Schema $schema) : array
{
return [
$this->extractSchemaFederation($schema, false),
......@@ -167,13 +167,9 @@ class SQLAzureFederationsSynchronizer extends AbstractSchemaSynchronizer
}
/**
* @param bool $isFederation
*
* @return Schema
*
* @throws RuntimeException
*/
private function extractSchemaFederation(Schema $schema, $isFederation)
private function extractSchemaFederation(Schema $schema, bool $isFederation) : Schema
{
$partitionedSchema = clone $schema;
......@@ -204,7 +200,7 @@ class SQLAzureFederationsSynchronizer extends AbstractSchemaSynchronizer
*
* @return string[]
*/
private function work(Schema $schema, Closure $operation)
private function work(Schema $schema, Closure $operation) : array
{
[$global, $federation] = $this->partitionSchema($schema);
$sql = [];
......@@ -235,10 +231,7 @@ class SQLAzureFederationsSynchronizer extends AbstractSchemaSynchronizer
return $sql;
}
/**
* @return string
*/
private function getFederationTypeDefaultValue()
private function getFederationTypeDefaultValue() : string
{
$federationType = Type::getType($this->shardManager->getDistributionType());
......@@ -259,10 +252,7 @@ class SQLAzureFederationsSynchronizer extends AbstractSchemaSynchronizer
return $defaultValue;
}
/**
* @return string
*/
private function getCreateFederationStatement()
private function getCreateFederationStatement() : string
{
$federationType = Type::getType($this->shardManager->getDistributionType());
$federationTypeSql = $federationType->getSQLDeclaration([], $this->conn->getDatabasePlatform());
......
......@@ -35,7 +35,7 @@ class SQLAzureShardManager implements ShardManager
/** @var Connection */
private $conn;
/** @var string|null */
/** @var mixed */
private $currentDistributionValue;
/**
......@@ -66,50 +66,40 @@ class SQLAzureShardManager implements ShardManager
/**
* Gets the name of the federation.
*
* @return string
*/
public function getFederationName()
public function getFederationName() : string
{
return $this->federationName;
}
/**
* Gets the distribution key.
*
* @return string
*/
public function getDistributionKey()
public function getDistributionKey() : string
{
return $this->distributionKey;
}
/**
* Gets the Doctrine Type name used for the distribution.
*
* @return string
*/
public function getDistributionType()
public function getDistributionType() : string
{
return $this->distributionType;
}
/**
* Sets Enabled/Disable filtering on the fly.
*
* @param bool $flag
*
* @return void
*/
public function setFilteringEnabled($flag)
public function setFilteringEnabled(bool $flag) : void
{
$this->filteringEnabled = (bool) $flag;
$this->filteringEnabled = $flag;
}
/**
* {@inheritDoc}
*/
public function selectGlobal()
public function selectGlobal() : void
{
if ($this->conn->isTransactionActive()) {
throw ActiveTransaction::new();
......@@ -123,7 +113,7 @@ class SQLAzureShardManager implements ShardManager
/**
* {@inheritDoc}
*/
public function selectShard($distributionValue)
public function selectShard($distributionValue) : void
{
if ($this->conn->isTransactionActive()) {
throw ActiveTransaction::new();
......@@ -153,7 +143,7 @@ class SQLAzureShardManager implements ShardManager
/**
* {@inheritDoc}
*/
public function getShards()
public function getShards() : array
{
$sql = 'SELECT member_id as id,
distribution_name as distribution_key,
......@@ -169,7 +159,7 @@ class SQLAzureShardManager implements ShardManager
/**
* {@inheritDoc}
*/
public function queryAll($sql, array $params = [], array $types = [])
public function queryAll(string $sql, array $params = [], array $types = []) : array
{
$shards = $this->getShards();
if (! $shards) {
......@@ -199,10 +189,8 @@ class SQLAzureShardManager implements ShardManager
* Splits Federation at a given distribution value.
*
* @param mixed $splitDistributionValue
*
* @return void
*/
public function splitFederation($splitDistributionValue)
public function splitFederation($splitDistributionValue) : void
{
$type = Type::getType($this->distributionType);
......
......@@ -54,11 +54,9 @@ class MultiTenantVisitor implements Visitor
private $distributionName;
/**
* @param string[] $excludedTables
* @param string $tenantColumnName
* @param string|null $distributionName
* @param string[] $excludedTables
*/
public function __construct(array $excludedTables = [], $tenantColumnName = 'tenant_id', $distributionName = null)
public function __construct(array $excludedTables = [], string $tenantColumnName = 'tenant_id', ?string $distributionName = null)
{
$this->excludedTables = $excludedTables;
$this->tenantColumnName = $tenantColumnName;
......@@ -94,13 +92,9 @@ class MultiTenantVisitor implements Visitor
}
/**
* @param Table $table
*
* @return Index
*
* @throws RuntimeException
*/
private function getClusteredIndex($table)
private function getClusteredIndex(Table $table) : Index
{
foreach ($table->getIndexes() as $index) {
if ($index->isPrimary() && ! $index->hasFlag('nonclustered')) {
......
......@@ -27,26 +27,22 @@ interface ShardManager
*
* This is the default database that is connected when no shard is
* selected.
*
* @return void
*/
public function selectGlobal();
public function selectGlobal() : void;
/**
* Selects the shard against which the queries after this statement will be issued.
*
* @param string $distributionValue
*
* @return void
* @param mixed $distributionValue
*
* @throws ShardingException If no value is passed as shard identifier.
*/
public function selectShard($distributionValue);
public function selectShard($distributionValue) : void;
/**
* Gets the distribution value currently used for sharding.
*
* @return string|null
* @return mixed
*/
public function getCurrentDistributionValue();
......@@ -58,7 +54,7 @@ interface ShardManager
*
* @return mixed[][]
*/
public function getShards();
public function getShards() : array;
/**
* Queries all shards in undefined order and return the results appended to
......@@ -66,11 +62,10 @@ interface ShardManager
*
* Using {@link \Doctrine\DBAL\Connection::fetchAll} to retrieve rows internally.
*
* @param string $sql
* @param mixed[] $params
* @param int[]|string[] $types
*
* @return mixed[]
*/
public function queryAll($sql, array $params, array $types);
public function queryAll(string $sql, array $params, array $types) : array;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment