Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Constraints/CheckConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@
*/
class CheckConstraint extends Constraint
{
/**
* @var string the SQL of the `CHECK` constraint.
*/
private string $expression;

public function getExpression(): string
{
return $this->expression;
}

/**
* @param string $value the SQL of the `CHECK` constraint.
*
* @return void
*/
public function setExpression(string $value): void
{
$this->expression = $value;
Expand Down
19 changes: 11 additions & 8 deletions src/Constraints/Constraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,8 @@
*/
class Constraint
{
/**
* @var array|string|null list of column names the constraint belongs to.
*/
private $columnNames;

/**
* @var object|string|null the constraint name.
*/
public $name;
private $name;

public function getColumnNames(): array
{
Expand All @@ -29,11 +22,21 @@ public function getName()
return $this->name;
}

/**
* @param array|string|null $value list of column names the constraint belongs to.
*
* @return void
*/
public function setColumnNames($value): void
{
$this->columnNames = $value;
}

/**
* @param object|string|null $value the constraint name.
*
* @return void
*/
public function setName($value): void
{
$this->name = $value;
Expand Down
30 changes: 15 additions & 15 deletions src/Constraints/ConstraintFinderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface ConstraintFinderInterface
*
* @return Constraint|null table primary key, `null` if the table has no primary key.
*/
public function getTablePrimaryKey($name, $refresh = false);
public function getTablePrimaryKey(string $name, bool $refresh = false): ?Constraint;

/**
* Returns primary keys for all tables in the database.
Expand All @@ -30,7 +30,7 @@ public function getTablePrimaryKey($name, $refresh = false);
* @return Constraint[] primary keys for all tables in the database.
* Each array element is an instance of {@see Constraint} or its child class.
*/
public function getSchemaPrimaryKeys(string $schema = '', bool $refresh = false);
public function getSchemaPrimaryKeys(string $schema = '', bool $refresh = false): array;

/**
* Obtains the foreign keys information for the named table.
Expand All @@ -40,7 +40,7 @@ public function getSchemaPrimaryKeys(string $schema = '', bool $refresh = false)
*
* @return ForeignKeyConstraint[] table foreign keys.
*/
public function getTableForeignKeys($name, $refresh = false);
public function getTableForeignKeys(string $name, bool $refresh = false): array;

/**
* Returns foreign keys for all tables in the database.
Expand All @@ -53,7 +53,7 @@ public function getTableForeignKeys($name, $refresh = false);
* @return ForeignKeyConstraint[][] foreign keys for all tables in the database. Each array element is an array of
* {@see ForeignKeyConstraint} or its child classes.
*/
public function getSchemaForeignKeys($schema = '', $refresh = false);
public function getSchemaForeignKeys(string $schema = '', bool $refresh = false): array;

/**
* Obtains the indexes information for the named table.
Expand All @@ -63,7 +63,7 @@ public function getSchemaForeignKeys($schema = '', $refresh = false);
*
* @return IndexConstraint[] table indexes.
*/
public function getTableIndexes($name, $refresh = false);
public function getTableIndexes(string $name, bool $refresh = false): array;

/**
* Returns indexes for all tables in the database.
Expand All @@ -76,7 +76,7 @@ public function getTableIndexes($name, $refresh = false);
* @return IndexConstraint[][] indexes for all tables in the database. Each array element is an array of
* {@see IndexConstraint} or its child classes.
*/
public function getSchemaIndexes($schema = '', $refresh = false);
public function getSchemaIndexes(string $schema = '', bool $refresh = false): array;

/**
* Obtains the unique constraints information for the named table.
Expand All @@ -86,7 +86,7 @@ public function getSchemaIndexes($schema = '', $refresh = false);
*
* @return Constraint[] table unique constraints.
*/
public function getTableUniques($name, $refresh = false);
public function getTableUniques(string $name, bool $refresh = false): array;

/**
* Returns unique constraints for all tables in the database.
Expand All @@ -96,10 +96,10 @@ public function getTableUniques($name, $refresh = false);
* @param bool $refresh whether to fetch the latest available table schemas. If this is false, cached data may be
* returned if available.
*
* @return Constraint[][] unique constraints for all tables in the database.
* Each array element is an array of [[Constraint]] or its child classes.
* @return Constraint[][] unique constraints for all tables in the database. Each array element is an array of
* {@see Constraint} or its child classes.
*/
public function getSchemaUniques($schema = '', $refresh = false);
public function getSchemaUniques(string $schema = '', bool $refresh = false): array;

/**
* Obtains the check constraints information for the named table.
Expand All @@ -109,7 +109,7 @@ public function getSchemaUniques($schema = '', $refresh = false);
*
* @return CheckConstraint[] table check constraints.
*/
public function getTableChecks($name, $refresh = false);
public function getTableChecks(string $name, bool $refresh = false): array;

/**
* Returns check constraints for all tables in the database.
Expand All @@ -122,17 +122,17 @@ public function getTableChecks($name, $refresh = false);
* @return CheckConstraint[][] check constraints for all tables in the database. Each array element is an array of
* {@see CheckConstraint} or its child classes.
*/
public function getSchemaChecks($schema = '', $refresh = false);
public function getSchemaChecks(string $schema = '', bool $refresh = false): array;

/**
* Obtains the default value constraints information for the named table.
*
* @param string $name table name. The table name may contain schema name if any. Do not quote the table name.
* @param bool $refresh whether to reload the information even if it is found in the cache.
* @param bool $refresh whether to reload the information even if it is found in the cache.
*
* @return DefaultValueConstraint[] table default value constraints.
*/
public function getTableDefaultValues($name, $refresh = false);
public function getTableDefaultValues(string $name, bool $refresh = false): array;

/**
* Returns default value constraints for all tables in the database.
Expand All @@ -145,5 +145,5 @@ public function getTableDefaultValues($name, $refresh = false);
* @return DefaultValueConstraint[] default value constraints for all tables in the database. Each array element is
* an array of {@see DefaultValueConstraint} or its child classes.
*/
public function getSchemaDefaultValues($schema = '', $refresh = false);
public function getSchemaDefaultValues(string $schema = '', bool $refresh = false): array;
}
70 changes: 35 additions & 35 deletions src/Constraints/ConstraintFinderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
/**
* ConstraintFinderTrait provides methods for getting a table constraint information.
*
* @property CheckConstraint[][] $schemaChecks Check constraints for all tables in the database.
* Each array element is an array of {@see CheckConstraint} or its child classes. This property is read-only.
* @property CheckConstraint[] $schemaChecks Check constraints for all tables in the database. Each array element is an
* array of {@see CheckConstraint} or its child classes. This property is read-only.
* @property DefaultValueConstraint[] $schemaDefaultValues Default value constraints for all tables in the database.
* Each array element is an array of {@see DefaultValueConstraint} or its child classes. This property is read-only.
* @property ForeignKeyConstraint[][] $schemaForeignKeys Foreign keys for all tables in the database. Each
* array element is an array of {@see ForeignKeyConstraint} or its child classes. This property is read-only.
* @property IndexConstraint[][] $schemaIndexes Indexes for all tables in the database. Each array element is
* @property ForeignKeyConstraint[] $schemaForeignKeys Foreign keys for all tables in the database. Each array element
* is an array of {@see ForeignKeyConstraint} or its child classes. This property is read-only.
* @property IndexConstraint[] $schemaIndexes Indexes for all tables in the database. Each array element is an array of
* {@see IndexConstraint} or its child classes. This property is read-only.
* @property Constraint[] $schemaPrimaryKeys Primary keys for all tables in the database. Each array element is an
* instance of {@see Constraint} or its child class. This property is read-only.
* @property IndexConstraint[] $schemaUniques Unique constraints for all tables in the database. Each array element is
* an array of {@see IndexConstraint} or its child classes. This property is read-only.
* @property Constraint[] $schemaPrimaryKeys Primary keys for all tables in the database. Each array element
* is an instance of {@see Constraint} or its child class. This property is read-only.
* @property IndexConstraint[][] $schemaUniques Unique constraints for all tables in the database.
* Each array element is an array of {@see IndexConstraint} or its child classes. This property is read-only.
*/
trait ConstraintFinderTrait
{
Expand Down Expand Up @@ -53,7 +53,7 @@ abstract protected function getSchemaMetadata(string $schema, string $type, bool
*
* @return Constraint|null primary key for the given table, `null` if the table has no primary key.
*/
abstract protected function loadTablePrimaryKey($tableName);
abstract protected function loadTablePrimaryKey(string $tableName): ?Constraint;

/**
* Loads all foreign keys for the given table.
Expand All @@ -62,7 +62,7 @@ abstract protected function loadTablePrimaryKey($tableName);
*
* @return ForeignKeyConstraint[] foreign keys for the given table.
*/
abstract protected function loadTableForeignKeys($tableName);
abstract protected function loadTableForeignKeys(string $tableName): array;

/**
* Loads all indexes for the given table.
Expand All @@ -71,7 +71,7 @@ abstract protected function loadTableForeignKeys($tableName);
*
* @return IndexConstraint[] indexes for the given table.
*/
abstract protected function loadTableIndexes($tableName);
abstract protected function loadTableIndexes(string $tableName): array;

/**
* Loads all unique constraints for the given table.
Expand All @@ -80,7 +80,7 @@ abstract protected function loadTableIndexes($tableName);
*
* @return Constraint[] unique constraints for the given table.
*/
abstract protected function loadTableUniques($tableName);
abstract protected function loadTableUniques(string $tableName): array;

/**
* Loads all check constraints for the given table.
Expand All @@ -89,7 +89,7 @@ abstract protected function loadTableUniques($tableName);
*
* @return CheckConstraint[] check constraints for the given table.
*/
abstract protected function loadTableChecks($tableName);
abstract protected function loadTableChecks(string $tableName): array;

/**
* Loads all default value constraints for the given table.
Expand All @@ -98,7 +98,7 @@ abstract protected function loadTableChecks($tableName);
*
* @return DefaultValueConstraint[] default value constraints for the given table.
*/
abstract protected function loadTableDefaultValues($tableName);
abstract protected function loadTableDefaultValues(string $tableName): array;

/**
* Obtains the primary key for the named table.
Expand All @@ -108,7 +108,7 @@ abstract protected function loadTableDefaultValues($tableName);
*
* @return Constraint|null table primary key, `null` if the table has no primary key.
*/
public function getTablePrimaryKey($name, $refresh = false)
public function getTablePrimaryKey(string $name, bool $refresh = false): ?Constraint
{
return $this->getTableMetadata($name, 'primaryKey', $refresh);
}
Expand All @@ -124,7 +124,7 @@ public function getTablePrimaryKey($name, $refresh = false)
* @return Constraint[] primary keys for all tables in the database. Each array element is an instance of
* {@see Constraint} or its child class.
*/
public function getSchemaPrimaryKeys(string $schema = '', bool $refresh = false)
public function getSchemaPrimaryKeys(string $schema = '', bool $refresh = false): array
{
return $this->getSchemaMetadata($schema, 'primaryKey', $refresh);
}
Expand All @@ -137,7 +137,7 @@ public function getSchemaPrimaryKeys(string $schema = '', bool $refresh = false)
*
* @return ForeignKeyConstraint[] table foreign keys.
*/
public function getTableForeignKeys($name, $refresh = false)
public function getTableForeignKeys(string $name, bool $refresh = false): array
{
return $this->getTableMetadata($name, 'foreignKeys', $refresh);
}
Expand All @@ -153,7 +153,7 @@ public function getTableForeignKeys($name, $refresh = false)
* @return ForeignKeyConstraint[][] foreign keys for all tables in the database. Each array element is an array of
* {@see ForeignKeyConstraint} or its child classes.
*/
public function getSchemaForeignKeys($schema = '', $refresh = false)
public function getSchemaForeignKeys(string $schema = '', bool $refresh = false): array
{
return $this->getSchemaMetadata($schema, 'foreignKeys', $refresh);
}
Expand All @@ -166,7 +166,7 @@ public function getSchemaForeignKeys($schema = '', $refresh = false)
*
* @return IndexConstraint[] table indexes.
*/
public function getTableIndexes($name, $refresh = false)
public function getTableIndexes(string $name, bool $refresh = false): array
{
return $this->getTableMetadata($name, 'indexes', $refresh);
}
Expand All @@ -179,10 +179,10 @@ public function getTableIndexes($name, $refresh = false)
* @param bool $refresh whether to fetch the latest available table schemas. If this is false, cached data may be
* returned if available.
*
* @return IndexConstraint[][] indexes for all tables in the database.
* Each array element is an array of {@see IndexConstraint} or its child classes.
* @return IndexConstraint[][] indexes for all tables in the database. Each array element is an array of
* {@see IndexConstraint} or its child classes.
*/
public function getSchemaIndexes($schema = '', $refresh = false)
public function getSchemaIndexes(string $schema = '', bool $refresh = false): array
{
return $this->getSchemaMetadata($schema, 'indexes', $refresh);
}
Expand All @@ -195,7 +195,7 @@ public function getSchemaIndexes($schema = '', $refresh = false)
*
* @return Constraint[] table unique constraints.
*/
public function getTableUniques($name, $refresh = false)
public function getTableUniques(string $name, bool $refresh = false): array
{
return $this->getTableMetadata($name, 'uniques', $refresh);
}
Expand All @@ -208,10 +208,10 @@ public function getTableUniques($name, $refresh = false)
* @param bool $refresh whether to fetch the latest available table schemas. If this is false, cached data may be
* returned if available.
*
* @return Constraint[][] unique constraints for all tables in the database.
* Each array element is an array of {@see Constraint} or its child classes.
* @return Constraint[][] unique constraints for all tables in the database. Each array element is an array of
* {@see Constraint} or its child classes.
*/
public function getSchemaUniques($schema = '', $refresh = false)
public function getSchemaUniques(string $schema = '', bool $refresh = false): array
{
return $this->getSchemaMetadata($schema, 'uniques', $refresh);
}
Expand All @@ -224,7 +224,7 @@ public function getSchemaUniques($schema = '', $refresh = false)
*
* @return CheckConstraint[] table check constraints.
*/
public function getTableChecks($name, $refresh = false)
public function getTableChecks(string $name, bool $refresh = false): array
{
return $this->getTableMetadata($name, 'checks', $refresh);
}
Expand All @@ -237,10 +237,10 @@ public function getTableChecks($name, $refresh = false)
* @param bool $refresh whether to fetch the latest available table schemas. If this is false, cached data may be
* returned if available.
*
* @return CheckConstraint[][] check constraints for all tables in the database.
* Each array element is an array of {@see CheckConstraint} or its child classes.
* @return CheckConstraint[][] check constraints for all tables in the database. Each array element is an array of
* {@see CheckConstraint} or its child classes.
*/
public function getSchemaChecks($schema = '', $refresh = false)
public function getSchemaChecks(string $schema = '', bool $refresh = false): array
{
return $this->getSchemaMetadata($schema, 'checks', $refresh);
}
Expand All @@ -253,7 +253,7 @@ public function getSchemaChecks($schema = '', $refresh = false)
*
* @return DefaultValueConstraint[] table default value constraints.
*/
public function getTableDefaultValues($name, $refresh = false)
public function getTableDefaultValues(string $name, bool $refresh = false): array
{
return $this->getTableMetadata($name, 'defaultValues', $refresh);
}
Expand All @@ -266,10 +266,10 @@ public function getTableDefaultValues($name, $refresh = false)
* @param bool $refresh whether to fetch the latest available table schemas. If this is false,
* cached data may be returned if available.
*
* @return DefaultValueConstraint[] default value constraints for all tables in the database.
* Each array element is an array of [[DefaultValueConstraint]] or its child classes.
* @return DefaultValueConstraint[] default value constraints for all tables in the database. Each array element is
* an array of {@see DefaultValueConstraint} or its child classes.
*/
public function getSchemaDefaultValues($schema = '', $refresh = false)
public function getSchemaDefaultValues(string $schema = '', bool $refresh = false): array
{
return $this->getSchemaMetadata($schema, 'defaultValues', $refresh);
}
Expand Down
Loading