Skip to content

Commit 318ec5c

Browse files
authored
Explicitly mark nullable parameters (#933)
1 parent a0021a1 commit 318ec5c

26 files changed

+72
-71
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
- Enh #926: Refactor `DbArrayHelper` (@Tigrov)
5959
- Enh #920: Move index constants to the appropriate DBMS driver's `IndexType` and `IndexMethod` classes (@Tigrov)
6060
- New #928: Add `ReferentialAction` class with constants of possible values of referential actions (@Tigrov)
61+
- Bug #933: Explicitly mark nullable parameters (@vjik)
6162

6263
## 1.3.0 March 21, 2024
6364

src/Cache/SchemaCache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function get(mixed $key): mixed
8181
* @throws InvalidArgumentException If the $key string isn't a legal value.
8282
* @throws RuntimeException If cache value isn't set.
8383
*/
84-
public function set(mixed $key, mixed $value, string $tag = null): void
84+
public function set(mixed $key, mixed $value, ?string $tag = null): void
8585
{
8686
$stringKey = $this->normalize($key);
8787

@@ -218,7 +218,7 @@ private function normalize(mixed $key): string
218218
*
219219
* @throws InvalidArgumentException
220220
*/
221-
private function addToTag(string $key, string $cacheTag = null): void
221+
private function addToTag(string $key, ?string $cacheTag = null): void
222222
{
223223
if (empty($cacheTag)) {
224224
return;

src/Command/AbstractCommand.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ public function addForeignKey(
161161
array|string $columns,
162162
string $referenceTable,
163163
array|string $referenceColumns,
164-
string $delete = null,
165-
string $update = null
164+
?string $delete = null,
165+
?string $update = null
166166
): static {
167167
$sql = $this->getQueryBuilder()->addForeignKey(
168168
$table,
@@ -219,7 +219,7 @@ public function insertBatch(string $table, iterable $rows, array $columns = []):
219219
return $this;
220220
}
221221

222-
abstract public function bindValue(int|string $name, mixed $value, int $dataType = null): static;
222+
abstract public function bindValue(int|string $name, mixed $value, ?int $dataType = null): static;
223223

224224
abstract public function bindValues(array $values): static;
225225

@@ -233,14 +233,14 @@ public function createIndex(
233233
string $table,
234234
string $name,
235235
array|string $columns,
236-
string $indexType = null,
237-
string $indexMethod = null
236+
?string $indexType = null,
237+
?string $indexMethod = null
238238
): static {
239239
$sql = $this->getQueryBuilder()->createIndex($table, $name, $columns, $indexType, $indexMethod);
240240
return $this->setSql($sql)->requireTableSchemaRefresh($table);
241241
}
242242

243-
public function createTable(string $table, array $columns, string $options = null): static
243+
public function createTable(string $table, array $columns, ?string $options = null): static
244244
{
245245
$sql = $this->getQueryBuilder()->createTable($table, $columns, $options);
246246
return $this->setSql($sql)->requireTableSchemaRefresh($table);
@@ -467,7 +467,7 @@ public function renameTable(string $table, string $newName): static
467467
return $this->setSql($sql)->requireTableSchemaRefresh($table);
468468
}
469469

470-
public function resetSequence(string $table, int|string $value = null): static
470+
public function resetSequence(string $table, int|string|null $value = null): static
471471
{
472472
$sql = $this->getQueryBuilder()->resetSequence($table, $value);
473473
return $this->setSql($sql);
@@ -604,7 +604,7 @@ protected function requireTableSchemaRefresh(string $name): static
604604
*
605605
* {@see \Yiisoft\Db\Transaction\TransactionInterface::begin()} for details.
606606
*/
607-
protected function requireTransaction(string $isolationLevel = null): static
607+
protected function requireTransaction(?string $isolationLevel = null): static
608608
{
609609
$this->isolationLevel = $isolationLevel;
610610
return $this;

src/Command/CommandInterface.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ public function insertBatch(string $table, iterable $rows, array $columns = []):
222222
public function bindParam(
223223
int|string $name,
224224
mixed &$value,
225-
int $dataType = null,
226-
int $length = null,
225+
?int $dataType = null,
226+
?int $length = null,
227227
mixed $driverOptions = null
228228
): static;
229229

@@ -251,7 +251,7 @@ public function addUnique(string $table, string $name, array|string $columns): s
251251
*
252252
* @psalm-param DataType::*|null $dataType
253253
*/
254-
public function bindValue(int|string $name, mixed $value, int $dataType = null): static;
254+
public function bindValue(int|string $name, mixed $value, ?int $dataType = null): static;
255255

256256
/**
257257
* Binds a list of values to the corresponding parameters.
@@ -311,8 +311,8 @@ public function createIndex(
311311
string $table,
312312
string $name,
313313
array|string $columns,
314-
string $indexType = null,
315-
string $indexMethod = null
314+
?string $indexType = null,
315+
?string $indexMethod = null
316316
): static;
317317

318318
/**
@@ -362,7 +362,7 @@ public function createIndex(
362362
*
363363
* @psalm-param array<string, ColumnInterface>|string[] $columns
364364
*/
365-
public function createTable(string $table, array $columns, string $options = null): static;
365+
public function createTable(string $table, array $columns, ?string $options = null): static;
366366

367367
/**
368368
* Creates a SQL View.
@@ -630,7 +630,7 @@ public function insertWithReturningPks(string $table, array $columns): bool|arra
630630
* @throws Exception If there is any DB error.
631631
* @throws InvalidConfigException
632632
*/
633-
public function prepare(bool $forRead = null): void;
633+
public function prepare(?bool $forRead = null): void;
634634

635635
/**
636636
* Executes the SQL statement and returns a query result.
@@ -733,7 +733,7 @@ public function renameTable(string $table, string $newName): static;
733733
*
734734
* Note: The method will quote the `table` parameter before using it in the generated SQL.
735735
*/
736-
public function resetSequence(string $table, int|string $value = null): static;
736+
public function resetSequence(string $table, int|string|null $value = null): static;
737737

738738
/**
739739
* List all database names in the current connection.

src/Connection/AbstractConnection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ abstract class AbstractConnection implements ConnectionInterface
2424
private bool $enableSavepoint = true;
2525
private string $tablePrefix = '';
2626

27-
public function beginTransaction(string $isolationLevel = null): TransactionInterface
27+
public function beginTransaction(?string $isolationLevel = null): TransactionInterface
2828
{
2929
$this->open();
3030
$this->transaction = $this->getTransaction();
@@ -73,7 +73,7 @@ public function setTablePrefix(string $value): void
7373
$this->tablePrefix = $value;
7474
}
7575

76-
public function transaction(Closure $closure, string $isolationLevel = null): mixed
76+
public function transaction(Closure $closure, ?string $isolationLevel = null): mixed
7777
{
7878
$transaction = $this->beginTransaction($isolationLevel);
7979
$level = $transaction->getLevel();

src/Connection/ConnectionInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ interface ConnectionInterface
4444
*
4545
* @return TransactionInterface The transaction initiated.
4646
*/
47-
public function beginTransaction(string $isolationLevel = null): TransactionInterface;
47+
public function beginTransaction(?string $isolationLevel = null): TransactionInterface;
4848

4949
/**
5050
* Create a batch query result instance.
@@ -69,7 +69,7 @@ public function createBatchQueryResult(QueryInterface $query, bool $each = false
6969
*
7070
* @psalm-param ParamsType $params
7171
*/
72-
public function createCommand(string $sql = null, array $params = []): CommandInterface;
72+
public function createCommand(?string $sql = null, array $params = []): CommandInterface;
7373

7474
/**
7575
* Create a transaction instance.
@@ -104,7 +104,7 @@ public function getDriverName(): string;
104104
*
105105
* @return string The row ID of the last row inserted, or the last value retrieved from the sequence object.
106106
*/
107-
public function getLastInsertID(string $sequenceName = null): string;
107+
public function getLastInsertID(?string $sequenceName = null): string;
108108

109109
/**
110110
* Returns the query builder for the current DB connection.
@@ -221,5 +221,5 @@ public function setTablePrefix(string $value): void;
221221
*
222222
* @psalm-param Closure(ConnectionInterface):mixed|Closure(ConnectionInterface):void $closure
223223
*/
224-
public function transaction(Closure $closure, string $isolationLevel = null): mixed;
224+
public function transaction(Closure $closure, ?string $isolationLevel = null): mixed;
225225
}

src/Debug/CommandInterfaceProxy.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ public function addForeignKey(
6868
array|string $columns,
6969
string $referenceTable,
7070
array|string $referenceColumns,
71-
string $delete = null,
72-
string $update = null
71+
?string $delete = null,
72+
?string $update = null
7373
): static {
7474
return new self($this->decorated->{__FUNCTION__}(...func_get_args()), $this->collector);
7575
}
@@ -112,8 +112,8 @@ public function insertBatch(string $table, iterable $rows, array $columns = []):
112112
public function bindParam(
113113
int|string $name,
114114
mixed &$value,
115-
int $dataType = null,
116-
int $length = null,
115+
?int $dataType = null,
116+
?int $length = null,
117117
mixed $driverOptions = null
118118
): static {
119119
return new self($this->decorated->{__FUNCTION__}(...func_get_args()), $this->collector);
@@ -122,7 +122,7 @@ public function bindParam(
122122
/**
123123
* @psalm-suppress MixedArgument
124124
*/
125-
public function bindValue(int|string $name, mixed $value, int $dataType = null): static
125+
public function bindValue(int|string $name, mixed $value, ?int $dataType = null): static
126126
{
127127
return new self($this->decorated->{__FUNCTION__}(...func_get_args()), $this->collector);
128128
}
@@ -155,16 +155,16 @@ public function createIndex(
155155
string $table,
156156
string $name,
157157
array|string $columns,
158-
string $indexType = null,
159-
string $indexMethod = null
158+
?string $indexType = null,
159+
?string $indexMethod = null
160160
): static {
161161
return new self($this->decorated->{__FUNCTION__}(...func_get_args()), $this->collector);
162162
}
163163

164164
/**
165165
* @psalm-suppress MixedArgument
166166
*/
167-
public function createTable(string $table, array $columns, string $options = null): static
167+
public function createTable(string $table, array $columns, ?string $options = null): static
168168
{
169169
return new self($this->decorated->{__FUNCTION__}(...func_get_args()), $this->collector);
170170
}
@@ -323,7 +323,7 @@ public function insertWithReturningPks(string $table, array $columns): bool|arra
323323
return $this->decorated->{__FUNCTION__}(...func_get_args());
324324
}
325325

326-
public function prepare(bool $forRead = null): void
326+
public function prepare(?bool $forRead = null): void
327327
{
328328
$this->decorated->{__FUNCTION__}(...func_get_args());
329329
}
@@ -443,7 +443,7 @@ public function renameTable(string $table, string $newName): static
443443
/**
444444
* @psalm-suppress MixedArgument
445445
*/
446-
public function resetSequence(string $table, int|string $value = null): static
446+
public function resetSequence(string $table, int|string|null $value = null): static
447447
{
448448
return new self($this->decorated->{__FUNCTION__}(...func_get_args()), $this->collector);
449449
}

src/Debug/ConnectionInterfaceProxy.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(
2727
/**
2828
* @psalm-suppress PossiblyUndefinedArrayOffset
2929
*/
30-
public function beginTransaction(string $isolationLevel = null): TransactionInterface
30+
public function beginTransaction(?string $isolationLevel = null): TransactionInterface
3131
{
3232
[$callStack] = debug_backtrace();
3333

@@ -42,7 +42,7 @@ public function createBatchQueryResult(QueryInterface $query, bool $each = false
4242
return $this->connection->createBatchQueryResult($query, $each);
4343
}
4444

45-
public function createCommand(string $sql = null, array $params = []): CommandInterface
45+
public function createCommand(?string $sql = null, array $params = []): CommandInterface
4646
{
4747
return new CommandInterfaceProxy(
4848
$this->connection->createCommand($sql, $params),
@@ -63,7 +63,7 @@ public function close(): void
6363
$this->connection->close();
6464
}
6565

66-
public function getLastInsertID(string $sequenceName = null): string
66+
public function getLastInsertID(?string $sequenceName = null): string
6767
{
6868
return $this->connection->getLastInsertID($sequenceName);
6969
}
@@ -144,7 +144,7 @@ public function setTablePrefix(string $value): void
144144
* @psalm-param Closure(self): mixed $closure
145145
* @psalm-suppress PossiblyUndefinedArrayOffset
146146
*/
147-
public function transaction(Closure $closure, string $isolationLevel = null): mixed
147+
public function transaction(Closure $closure, ?string $isolationLevel = null): mixed
148148
{
149149
[$callStack] = debug_backtrace();
150150

src/Debug/TransactionInterfaceDecorator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __construct(
1717
/**
1818
* @psalm-suppress PossiblyUndefinedArrayOffset
1919
*/
20-
public function begin(string $isolationLevel = null): void
20+
public function begin(?string $isolationLevel = null): void
2121
{
2222
[$callStack] = debug_backtrace();
2323

src/Driver/Pdo/AbstractPdoConnection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function __sleep(): array
7979
return array_keys($fields);
8080
}
8181

82-
public function beginTransaction(string $isolationLevel = null): TransactionInterface
82+
public function beginTransaction(?string $isolationLevel = null): TransactionInterface
8383
{
8484
$transaction = parent::beginTransaction($isolationLevel);
8585
if ($this->logger !== null && $transaction instanceof LoggerAwareInterface) {
@@ -156,7 +156,7 @@ public function getPDO(): PDO|null
156156
return $this->pdo;
157157
}
158158

159-
public function getLastInsertID(string $sequenceName = null): string
159+
public function getLastInsertID(?string $sequenceName = null): string
160160
{
161161
if ($this->pdo !== null) {
162162
return $this->pdo->lastInsertID($sequenceName ?? null);

0 commit comments

Comments
 (0)