Skip to content

Commit 3fb5bb1

Browse files
committed
added PHP 8 typehints
1 parent 0ffbd6a commit 3fb5bb1

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
@@ -155,10 +155,7 @@ public function rollBack(): void
155155
}
156156

157157

158-
/**
159-
* @return mixed
160-
*/
161-
public function transaction(callable $callback)
158+
public function transaction(callable $callback): mixed
162159
{
163160
$this->beginTransaction();
164161
try {
@@ -227,9 +224,8 @@ public function fetch(string $sql, ...$params): ?Row
227224

228225
/**
229226
* Shortcut for query()->fetchField()
230-
* @return mixed
231227
*/
232-
public function fetchField(string $sql, ...$params)
228+
public function fetchField(string $sql, ...$params): mixed
233229
{
234230
return $this->query($sql, ...$params)->fetchField();
235231
}

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($callback);
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
@@ -244,9 +244,8 @@ public function fetch(): ?Row
244244

245245
/**
246246
* Fetches single field.
247-
* @return mixed
248247
*/
249-
public function fetchField($column = 0)
248+
public function fetchField(int $column = 0): mixed
250249
{
251250
if (func_num_args()) {
252251
trigger_error(__METHOD__ . '() argument is deprecated.', E_USER_DEPRECATED);
@@ -271,7 +270,7 @@ public function fetchFields(): ?array
271270
* @param string|int $key column name used for an array key or null for numeric index
272271
* @param string|int $value column name used for an array value or null for the whole row
273272
*/
274-
public function fetchPairs($key = null, $value = null): array
273+
public function fetchPairs(string|int $key = null, string|int $value = null): array
275274
{
276275
return Helpers::toPairs($this->fetchAll(), $key, $value);
277276
}
@@ -292,7 +291,6 @@ public function fetchAll(): array
292291

293292
/**
294293
* Fetches all rows and returns associative tree.
295-
* @param string $path associative descriptor
296294
*/
297295
public function fetchAssoc(string $path): array
298296
{

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)