Skip to content

Commit ea9495a

Browse files
authored
Merge pull request #63175 from nextcloud/carl/type-dbal
refactor(dbal): Adjust types of some strings
2 parents ea90ea1 + 78d3318 commit ea9495a

5 files changed

Lines changed: 29 additions & 11 deletions

File tree

lib/private/DB/Schema/Index.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public function getWrappedIndex(): DBALIndex {
3030

3131
#[\Override]
3232
public function getName(): string {
33-
return $this->index->getName();
33+
/** @var non-empty-string $name */
34+
$name = $this->index->getName();
35+
return $name;
3436
}
3537

3638
#[\Override]

lib/private/DB/Schema/Table.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ public function getIndexes(): array {
256256
));
257257
}
258258

259+
#[\Override]
260+
public function getIndex(string $name): IIndex {
261+
return new Index($this->table->getIndex($name));
262+
}
263+
259264
#[\Override]
260265
public function getForeignKeys(): array {
261266
return array_values(array_map(

lib/public/AppFramework/Db/SnowflakeAwareEntity.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace OCP\AppFramework\Db;
1010

1111
use OCP\AppFramework\Attribute\Consumable;
12-
use OCP\DB\Types;
12+
use OCP\DB\Schema\ColumnType;
1313
use OCP\Server;
1414
use OCP\Snowflake\ISnowflakeDecoder;
1515
use OCP\Snowflake\ISnowflakeGenerator;
@@ -24,8 +24,8 @@
2424
abstract class SnowflakeAwareEntity extends Entity {
2525
protected ?Snowflake $snowflake = null;
2626

27-
/** @psalm-param $_fieldTypes array<string, Types::*> */
28-
protected array $_fieldTypes = ['id' => Types::STRING];
27+
/** @psalm-param $_fieldTypes array<string, ColumnType> */
28+
protected array $_fieldTypes = ['id' => ColumnType::String];
2929

3030
/**
3131
* @since 33.0.0

lib/public/DB/Schema/IIndex.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface IIndex {
2121
/**
2222
* Returns the name of this index.
2323
*
24+
* @return non-empty-string
2425
* @since 35.0.0
2526
*/
2627
public function getName(): string;

lib/public/DB/Schema/ITable.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function getName(): string;
3131
* Sets the Primary Key.
3232
*
3333
* @param list<non-empty-string> $columnNames
34-
* @param string|false $indexName
34+
* @param non-empty-string|false $indexName
3535
*
3636
* @throws SchemaException
3737
* @since 35.0.0
@@ -40,6 +40,7 @@ public function setPrimaryKey(array $columnNames, string|false $indexName = fals
4040

4141
/**
4242
* @param list<non-empty-lowercase-string> $columnNames
43+
* @param ?non-empty-string $indexName
4344
* @param list<non-empty-lowercase-string> $flags
4445
* @param array<non-empty-lowercase-string, mixed> $options
4546
*
@@ -79,7 +80,7 @@ public function getPrimaryKey(): ?IIndex;
7980
/**
8081
* Drops an index from this table.
8182
*
82-
* @param non-empty-lowercase-string $name The index name.
83+
* @param non-empty-string $name The index name.
8384
*
8485
* @throws SchemaException If the index does not exist.
8586
* @since 35.0.0
@@ -89,14 +90,14 @@ public function dropIndex(string $name): self;
8990
/**
9091
* Returns whether this table has an index with the given name.
9192
*
92-
* @param non-empty-lowercase-string $name The index name.
93+
* @param non-empty-string $name The index name.
9394
* @since 35.0.0
9495
*/
9596
public function hasIndex(string $name): bool;
9697

9798
/**
9899
* @param list<string> $columnNames
99-
* @param string|null $indexName
100+
* @param non-empty-string|null $indexName
100101
* @param array<string, mixed> $options
101102
*
102103
* @throws SchemaException
@@ -107,9 +108,9 @@ public function addUniqueIndex(array $columnNames, ?string $indexName = null, ar
107108
/**
108109
* Renames an index.
109110
*
110-
* @param non-empty-lowercase-string $oldName The name of the index to rename from.
111-
* @param non-empty-lowercase-string|null $newName The name of the index to rename to.
112-
* If null is given, the index name will be auto-generated.
111+
* @param non-empty-string $oldName The name of the index to rename from.
112+
* @param non-empty-string|null $newName The name of the index to rename to.
113+
* If null is given, the index name will be auto-generated.
113114
*
114115
* @return self This table instance.
115116
*
@@ -200,6 +201,15 @@ public function getColumns(): array;
200201
*/
201202
public function getIndexes(): array;
202203

204+
/**
205+
* Returns a specific index by name of this table.
206+
*
207+
* @param non-empty-string $name The index name.
208+
* @return IIndex
209+
* @since 35.0.0
210+
*/
211+
public function getIndex(string $name): IIndex;
212+
203213
/**
204214
* Adds a foreign key constraint.
205215
*

0 commit comments

Comments
 (0)