Add return type `static` for `@return $this`
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / database / table / index / DatabaseTableIndex.class.php
index eab46468b9bbd1a97146b8f6ddf17f7aba739e26..b2cda9355ffffd33c587863ca5d2f057ea5dc707 100644 (file)
@@ -13,7 +13,7 @@ use wcf\system\database\table\TDroppableDatabaseComponent;
  * @package WoltLabSuite\Core\System\Database\Table\Index
  * @since   5.2
  */
-class DatabaseTableIndex
+final class DatabaseTableIndex
 {
     use TDroppableDatabaseComponent;
 
@@ -21,25 +21,22 @@ class DatabaseTableIndex
      * 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;
 
@@ -51,10 +48,8 @@ class DatabaseTableIndex
 
     /**
      * Creates a new `DatabaseTableIndex` object.
-     *
-     * @param string $name column name
      */
-    protected function __construct($name)
+    private function __construct(string $name)
     {
         $this->name = $name;
     }
@@ -63,9 +58,9 @@ class DatabaseTableIndex
      * 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);
 
@@ -75,10 +70,9 @@ class DatabaseTableIndex
     /**
      * 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;
@@ -91,7 +85,7 @@ class DatabaseTableIndex
      *
      * @return  string[]
      */
-    public function getColumns()
+    public function getColumns(): array
     {
         if (!isset($this->columns)) {
             throw new \BadMethodCallException(
@@ -105,9 +99,9 @@ class DatabaseTableIndex
     /**
      * 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()),
@@ -117,30 +111,24 @@ class DatabaseTableIndex
 
     /**
      * 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;
     }
@@ -148,10 +136,9 @@ class DatabaseTableIndex
     /**
      * 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;
 
@@ -161,11 +148,9 @@ class DatabaseTableIndex
     /**
      * 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
@@ -183,11 +168,8 @@ class DatabaseTableIndex
 
     /**
      * 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);
     }
@@ -195,13 +177,11 @@ class DatabaseTableIndex
     /**
      * 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']);
     }