Skip to content

Commit 6906801

Browse files
committed
added PHP 8 typehints
1 parent b76cb9e commit 6906801

13 files changed

Lines changed: 51 additions & 102 deletions

src/Database/Connection.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,7 @@ public function rollBack(): void
179179
}
180180

181181

182-
/**
183-
* @return mixed
184-
*/
185-
public function transaction(callable $callback)
182+
public function transaction(callable $callback): mixed
186183
{
187184
if ($this->transactionDepth === 0) {
188185
$this->beginTransaction();
@@ -263,9 +260,8 @@ public function fetch(string $sql, ...$params): ?Row
263260

264261
/**
265262
* Shortcut for query()->fetchField()
266-
* @return mixed
267263
*/
268-
public function fetchField(string $sql, ...$params)
264+
public function fetchField(string $sql, ...$params): mixed
269265
{
270266
return $this->query($sql, ...$params)->fetchField();
271267
}

src/Database/Conventions.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ interface Conventions
1616
{
1717
/**
1818
* Returns primary key for table.
19-
* @return string|string[]|null
2019
*/
21-
function getPrimary(string $table);
20+
function getPrimary(string $table): string|array|null;
2221

2322
/**
2423
* Returns referenced table & referenced column.

src/Database/Conventions/DiscoveredConventions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(IStructure $structure)
2727
}
2828

2929

30-
public function getPrimary(string $table)
30+
public function getPrimary(string $table): string|array|null
3131
{
3232
return $this->structure->getPrimaryKey($table);
3333
}

src/Database/Driver.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ function formatLike(string $value, int $pos): string;
5555

5656
/**
5757
* Injects LIMIT/OFFSET to the SQL query.
58-
* @param string $sql query that will be modified.
5958
*/
6059
function applyLimit(string &$sql, ?int $limit, ?int $offset): void;
6160

src/Database/DriverException.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ class DriverException extends \PDOException
2020
public ?array $params = null;
2121

2222

23-
/**
24-
* @return static
25-
*/
26-
public static function from(\PDOException $src)
23+
public static function from(\PDOException $src): static
2724
{
2825
$e = new static($src->message, 0, $src);
2926
$e->file = $src->file;
@@ -41,10 +38,7 @@ public static function from(\PDOException $src)
4138
}
4239

4340

44-
/**
45-
* @return int|string|null Driver-specific error code
46-
*/
47-
public function getDriverCode()
41+
public function getDriverCode(): int|string|null
4842
{
4943
return $this->errorInfo[1] ?? null;
5044
}

src/Database/Explorer.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ public function rollBack(): void
6060
}
6161

6262

63-
/**
64-
* @return mixed
65-
*/
66-
public function transaction(callable $callback)
63+
public function transaction(callable $callback): mixed
6764
{
6865
return $this->connection->transaction(fn() => $callback($this));
6966
}
@@ -128,9 +125,8 @@ public function fetch(string $sql, ...$params): ?Row
128125

129126
/**
130127
* Shortcut for query()->fetchField()
131-
* @return mixed
132128
*/
133-
public function fetchField(string $sql, ...$params)
129+
public function fetchField(string $sql, ...$params): mixed
134130
{
135131
return $this->connection->query($sql, ...$params)->fetchField();
136132
}

src/Database/IStructure.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function getColumns(string $table): array;
4141
* Returns table primary key.
4242
* @return string|string[]|null
4343
*/
44-
function getPrimaryKey(string $table);
44+
function getPrimaryKey(string $table): string|array|null;
4545

4646
/**
4747
* Returns autoincrement primary key name.

src/Database/ResultSet.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,8 @@ public function fetch(): ?Row
218218

219219
/**
220220
* Fetches single field.
221-
* @return mixed
222221
*/
223-
public function fetchField($column = 0)
222+
public function fetchField(int $column = 0): mixed
224223
{
225224
if (func_num_args()) {
226225
trigger_error(__METHOD__ . '() argument is deprecated.', E_USER_DEPRECATED);
@@ -245,7 +244,7 @@ public function fetchFields(): ?array
245244
* @param string|int $key column name used for an array key or null for numeric index
246245
* @param string|int $value column name used for an array value or null for the whole row
247246
*/
248-
public function fetchPairs($key = null, $value = null): array
247+
public function fetchPairs(string|int $key = null, string|int $value = null): array
249248
{
250249
return Helpers::toPairs($this->fetchAll(), $key, $value);
251250
}
@@ -266,7 +265,6 @@ public function fetchAll(): array
266265

267266
/**
268267
* Fetches all rows and returns associative tree.
269-
* @param string $path associative descriptor
270268
*/
271269
public function fetchAssoc(string $path): array
272270
{

src/Database/Row.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ public function __isset($key)
3333
/**
3434
* Returns a item.
3535
* @param string|int $key key or index
36-
* @return mixed
3736
*/
38-
public function offsetGet($key)
37+
public function offsetGet($key): mixed
3938
{
4039
if (is_int($key)) {
4140
$arr = array_slice((array) $this, $key, 1);

src/Database/Structure.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function getColumns(string $table): array
5454
/**
5555
* @return string|string[]|null
5656
*/
57-
public function getPrimaryKey(string $table)
57+
public function getPrimaryKey(string $table): string|array|null
5858
{
5959
$this->needStructure();
6060
$table = $this->resolveFQTableName($table);

0 commit comments

Comments
 (0)