Skip to content

Commit

Permalink
Clean code Constraints::class. (#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Feb 27, 2023
1 parent a8ef62e commit 21fd145
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 15 deletions.
6 changes: 5 additions & 1 deletion src/Constraint/CheckConstraint.php
Expand Up @@ -15,18 +15,22 @@ final class CheckConstraint extends Constraint
{
private string $expression = '';

/**
* @return string The SQL of the `CHECK` constraint.
*/
public function getExpression(): string
{
return $this->expression;
}

/**
* Set the SQL of the `CHECK` constraint.
*
* @param string $value The SQL of the `CHECK` constraint.
*/
public function expression(string $value): self
{
$this->expression = $value;

return $this;
}
}
16 changes: 10 additions & 6 deletions src/Constraint/Constraint.php
Expand Up @@ -13,37 +13,41 @@ class Constraint
private string|array|null $columnNames = null;
private string|null|object $name = null;

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

/**
* @return object|string|null The constraint name.
*/
public function getName(): object|string|null
{
return $this->name;
}

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

return $this;
}

/**
* @param object|string|null $value The constraint name.
* Set the constraint name.
*
* @return static
* @param object|string|null $value The constraint name.
*/
public function name(object|string|null $value): static
{
$this->name = $value;

return $this;
}
}
6 changes: 5 additions & 1 deletion src/Constraint/DefaultValueConstraint.php
Expand Up @@ -15,18 +15,22 @@ final class DefaultValueConstraint extends Constraint
{
private mixed $value = null;

/**
* @return mixed The default value as returned by the DBMS.
*/
public function getValue(): mixed
{
return $this->value;
}

/**
* Set the default value as returned by the DBMS.
*
* @param mixed $value The default value as returned by the DBMS.
*/
public function value(mixed $value): self
{
$this->value = $value;

return $this;
}
}
30 changes: 25 additions & 5 deletions src/Constraint/ForeignKeyConstraint.php
Expand Up @@ -18,78 +18,98 @@ final class ForeignKeyConstraint extends Constraint
private string|null $onUpdate = null;
private string|null $onDelete = null;

/**
* @return string|null The foreign table schema name.
*/
public function getForeignSchemaName(): string|null
{
return $this->foreignSchemaName;
}

/**
* @return string|null The foreign table name.
*/
public function getForeignTableName(): string|null
{
return $this->foreignTableName;
}

/**
* @return array The list of foreign table column names.
*/
public function getForeignColumnNames(): array
{
return $this->foreignColumnNames;
}

/**
* @return string|null The referential action if rows in a referenced table are to be updated.
*/
public function getOnUpdate(): string|null
{
return $this->onUpdate;
}

/**
* @return string|null The referential action if rows in a referenced table are to be deleted.
*/
public function getOnDelete(): string|null
{
return $this->onDelete;
}

/**
* Set the foreign table schema name.
*
* @param string|null $value the referenced table schema name.
*/
public function foreignSchemaName(string|null $value): self
{
$this->foreignSchemaName = $value;

return $this;
}

/**
* Set the foreign table name.
*
* @param string|null $value The referenced table name.
*/
public function foreignTableName(string|null $value): self
{
$this->foreignTableName = $value;

return $this;
}

/**
* Set the list of foreign table column names.
*
* @param array $value The list of referenced table column names.
*/
public function foreignColumnNames(array $value): self
{
$this->foreignColumnNames = $value;

return $this;
}

/**
* Set the referential action if rows in a referenced table are to be updated.
*
* @param string|null $value The referential action if rows in a referenced table are to be updated.
*/
public function onUpdate(string|null $value): self
{
$this->onUpdate = $value;

return $this;
}

/**
* Set the referential action if rows in a referenced table are to be deleted.
*
* @param string|null $value The referential action if rows in a referenced table are to be deleted.
*/
public function onDelete(string|null $value): self
{
$this->onDelete = $value;

return $this;
}
}
12 changes: 10 additions & 2 deletions src/Constraint/IndexConstraint.php
Expand Up @@ -15,33 +15,41 @@ final class IndexConstraint extends Constraint
private bool $isUnique = false;
private bool $isPrimary = false;

/**
* @return bool whether the index is unique.
*/
public function isUnique(): bool
{
return $this->isUnique;
}

/**
* @return bool whether the index was created for a primary key.
*/
public function isPrimary(): bool
{
return $this->isPrimary;
}

/**
* Set whether the index is unique.
*
* @param bool $value whether the index is unique.
*/
public function unique(bool $value): self
{
$this->isUnique = $value;

return $this;
}

/**
* Set whether the index was created for a primary key.
*
* @param bool $value whether the index was created for a primary key.
*/
public function primary(bool $value): self
{
$this->isPrimary = $value;

return $this;
}
}

0 comments on commit 21fd145

Please sign in to comment.