* @package WoltLabSuite\Core\System\Database\Table\Index
* @since 5.2
*/
-class DatabaseTableIndex
+final class DatabaseTableIndex
{
use TDroppableDatabaseComponent;
* indexed columns
* @var string[]
*/
- protected $columns;
+ private array $columns;
/**
* is `true` if index name has been automatically generated
- * @var bool
*/
- protected $generatedName = false;
+ private bool $generatedName = false;
/**
* name of index
- * @var string
*/
- protected $name;
+ private string $name;
/**
* type of index (see `*_TYPE` constants)
- * @var null|string
*/
- protected $type;
+ private ?string $type = null;
const DEFAULT_TYPE = null;
/**
* Creates a new `DatabaseTableIndex` object.
- *
- * @param string $name column name
*/
- protected function __construct($name)
+ private function __construct(string $name)
{
$this->name = $name;
}
* Sets the indexed columns and returns the index.
*
* @param string[] $columns indexed columns
- * @return $this this index
+ * @return $this
*/
- public function columns($columns)
+ public function columns(array $columns): static
{
$this->columns = \array_values($columns);
/**
* Sets the automatically generated name of the index.
*
- * @param string $name index name
- * @return $this this index
+ * @return $this
*/
- public function generatedName($name)
+ public function generatedName(string $name): static
{
$this->name($name);
$this->generatedName = true;
*
* @return string[]
*/
- public function getColumns()
+ public function getColumns(): array
{
if (!isset($this->columns)) {
throw new \BadMethodCallException(
/**
* Returns the data used by `DatabaseEditor` to add the index to a table.
*
- * @return array
+ * @return array{columns: string, type: string}
*/
- public function getData()
+ public function getData(): array
{
return [
'columns' => \implode(',', $this->getColumns()),
/**
* Returns the name of the index.
- *
- * @return string
*/
- public function getName()
+ public function getName(): string
{
return $this->name;
}
/**
* Returns the type of the index (see `*_TYPE` constants).
- *
- * @return null|string
*/
- public function getType()
+ public function getType(): ?string
{
return $this->type;
}
/**
* Returns `true` if the name of the index has been automatically generated.
- *
- * @return bool
*/
- public function hasGeneratedName()
+ public function hasGeneratedName(): bool
{
return $this->generatedName;
}
/**
* Sets the name of the index.
*
- * @param string $name index name
- * @return $this this index
+ * @return $this
*/
- public function name($name)
+ public function name(string $name): static
{
$this->name = $name;
/**
* Sets the type of the index and returns the index
*
- * @param null|string $type index type
- * @return $this this index
* @throws \InvalidArgumentException if given type is invalid
*/
- public function type($type)
+ public function type(?string $type): static
{
if (
$type !== static::DEFAULT_TYPE
/**
* Returns a `DatabaseTableIndex` object with the given name.
- *
- * @param string $name
- * @return static
*/
- public static function create($name = '')
+ public static function create(string $name): static
{
return new static($name);
}
/**
* Returns a `DatabaseTableIndex` object with the given name and data.
*
- * @param string $name
* @param array $data data returned by `DatabaseEditor::getIndexInformation()`
- * @return static
*/
- public static function createFromData($name, array $data)
+ public static function createFromData(string $name, array $data): static
{
- return static::create($name)
+ return self::create($name)
->type($data['type'])
->columns($data['columns']);
}