1
0
mirror of https://github.com/dg/dibi.git synced 2025-02-22 09:53:11 +01:00

cs nullable typehints

This commit is contained in:
David Grudl 2021-12-12 17:39:07 +01:00
parent 0f045c0986
commit 82150d120d
26 changed files with 67 additions and 67 deletions

View File

@ -26,7 +26,7 @@ class DibiExtension22 extends Nette\DI\CompilerExtension
private $cliMode;
public function __construct(bool $debugMode = null, bool $cliMode = null)
public function __construct(?bool $debugMode = null, ?bool $cliMode = null)
{
$this->debugMode = $debugMode;
$this->cliMode = $cliMode;

View File

@ -35,7 +35,7 @@ class Panel implements Tracy\IBarPanel
private $events = [];
public function __construct($explain = true, int $filter = null)
public function __construct($explain = true, ?int $filter = null)
{
$this->filter = $filter ?: Event::QUERY;
$this->explain = $explain;

View File

@ -68,7 +68,7 @@ class Connection implements IConnection
* - onConnect (array) => list of SQL queries to execute (by Connection::query()) after connection is established
* @throws Exception
*/
public function __construct(array $config, string $name = null)
public function __construct(array $config, ?string $name = null)
{
Helpers::alias($config, 'username', 'user');
Helpers::alias($config, 'password', 'pass');
@ -192,7 +192,7 @@ class Connection implements IConnection
* @see self::__construct
* @return mixed
*/
final public function getConfig(string $key = null, $default = null)
final public function getConfig(?string $key = null, $default = null)
{
return $key === null
? $this->config
@ -327,7 +327,7 @@ class Connection implements IConnection
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
* @throws Exception
*/
public function getInsertId(string $sequence = null): int
public function getInsertId(?string $sequence = null): int
{
if (!$this->driver) {
$this->connect();
@ -345,7 +345,7 @@ class Connection implements IConnection
/**
* Begins a transaction (if supported).
*/
public function begin(string $savepoint = null): void
public function begin(?string $savepoint = null): void
{
if ($this->transactionDepth !== 0) {
throw new \LogicException(__METHOD__ . '() call is forbidden inside a transaction() callback');
@ -374,7 +374,7 @@ class Connection implements IConnection
/**
* Commits statements in a transaction.
*/
public function commit(string $savepoint = null): void
public function commit(?string $savepoint = null): void
{
if ($this->transactionDepth !== 0) {
throw new \LogicException(__METHOD__ . '() call is forbidden inside a transaction() callback');
@ -403,7 +403,7 @@ class Connection implements IConnection
/**
* Rollback changes in a transaction.
*/
public function rollback(string $savepoint = null): void
public function rollback(?string $savepoint = null): void
{
if ($this->transactionDepth !== 0) {
throw new \LogicException(__METHOD__ . '() call is forbidden inside a transaction() callback');
@ -602,7 +602,7 @@ class Connection implements IConnection
* @param callable $onProgress function (int $count, ?float $percent): void
* @return int count of sql commands
*/
public function loadFile(string $file, callable $onProgress = null): int
public function loadFile(string $file, ?callable $onProgress = null): int
{
return Helpers::loadFromFile($this, $file, $onProgress);
}

View File

@ -65,7 +65,7 @@ class DataSource implements IDataSource
* @param string|array $col column name or array of column names
* @param string $as column alias
*/
public function select($col, string $as = null): self
public function select($col, ?string $as = null): self
{
if (is_array($col)) {
$this->cols = $col;
@ -111,7 +111,7 @@ class DataSource implements IDataSource
/**
* Limits number of rows.
*/
public function applyLimit(int $limit, int $offset = null): self
public function applyLimit(int $limit, ?int $offset = null): self
{
$this->limit = $limit;
$this->offset = $offset;
@ -188,7 +188,7 @@ class DataSource implements IDataSource
/**
* Fetches all records from table like $key => $value pairs.
*/
public function fetchPairs(string $key = null, string $value = null): array
public function fetchPairs(?string $key = null, ?string $value = null): array
{
return $this->getResult()->fetchPairs($key, $value);
}

View File

@ -20,7 +20,7 @@ class DateTime extends \DateTimeImmutable
/**
* @param string|int $time
*/
public function __construct($time = 'now', \DateTimeZone $timezone = null)
public function __construct($time = 'now', ?\DateTimeZone $timezone = null)
{
$timezone = $timezone ?: new \DateTimeZone(date_default_timezone_get());
if (is_numeric($time)) {

View File

@ -42,17 +42,17 @@ class DummyDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
}
public function begin(string $savepoint = null): void
public function begin(?string $savepoint = null): void
{
}
public function commit(string $savepoint = null): void
public function commit(?string $savepoint = null): void
{
}
public function rollback(string $savepoint = null): void
public function rollback(?string $savepoint = null): void
{
}

View File

@ -131,7 +131,7 @@ class FirebirdDriver implements Dibi\Driver
* Begins a transaction (if supported).
* @throws Dibi\DriverException
*/
public function begin(string $savepoint = null): void
public function begin(?string $savepoint = null): void
{
if ($savepoint !== null) {
throw new Dibi\NotSupportedException('Savepoints are not supported in Firebird/Interbase.');
@ -146,7 +146,7 @@ class FirebirdDriver implements Dibi\Driver
* Commits statements in a transaction.
* @throws Dibi\DriverException
*/
public function commit(string $savepoint = null): void
public function commit(?string $savepoint = null): void
{
if ($savepoint !== null) {
throw new Dibi\NotSupportedException('Savepoints are not supported in Firebird/Interbase.');
@ -164,7 +164,7 @@ class FirebirdDriver implements Dibi\Driver
* Rollback changes in a transaction.
* @throws Dibi\DriverException
*/
public function rollback(string $savepoint = null): void
public function rollback(?string $savepoint = null): void
{
if ($savepoint !== null) {
throw new Dibi\NotSupportedException('Savepoints are not supported in Firebird/Interbase.');

View File

@ -215,7 +215,7 @@ class FirebirdReflector implements Dibi\Reflector
* Returns metadata for all triggers in a table or database.
* (Only if user has permissions on ALTER TABLE, INSERT/UPDATE/DELETE record in table)
*/
public function getTriggersMeta(string $table = null): array
public function getTriggersMeta(?string $table = null): array
{
$res = $this->driver->query(
"
@ -263,7 +263,7 @@ class FirebirdReflector implements Dibi\Reflector
* Returns list of triggers for given table.
* (Only if user has permissions on ALTER TABLE, INSERT/UPDATE/DELETE record in table)
*/
public function getTriggers(string $table = null): array
public function getTriggers(?string $table = null): array
{
$q = 'SELECT TRIM(RDB$TRIGGER_NAME)
FROM RDB$TRIGGERS

View File

@ -222,7 +222,7 @@ class MySqliDriver implements Dibi\Driver
* Begins a transaction (if supported).
* @throws Dibi\DriverException
*/
public function begin(string $savepoint = null): void
public function begin(?string $savepoint = null): void
{
$this->query($savepoint ? "SAVEPOINT $savepoint" : 'START TRANSACTION');
}
@ -232,7 +232,7 @@ class MySqliDriver implements Dibi\Driver
* Commits statements in a transaction.
* @throws Dibi\DriverException
*/
public function commit(string $savepoint = null): void
public function commit(?string $savepoint = null): void
{
$this->query($savepoint ? "RELEASE SAVEPOINT $savepoint" : 'COMMIT');
}
@ -242,7 +242,7 @@ class MySqliDriver implements Dibi\Driver
* Rollback changes in a transaction.
* @throws Dibi\DriverException
*/
public function rollback(string $savepoint = null): void
public function rollback(?string $savepoint = null): void
{
$this->query($savepoint ? "ROLLBACK TO SAVEPOINT $savepoint" : 'ROLLBACK');
}

View File

@ -123,7 +123,7 @@ class OdbcDriver implements Dibi\Driver
* Begins a transaction (if supported).
* @throws Dibi\DriverException
*/
public function begin(string $savepoint = null): void
public function begin(?string $savepoint = null): void
{
if (!odbc_autocommit($this->connection, PHP_VERSION_ID < 80000 ? 0 : false)) {
throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection));
@ -135,7 +135,7 @@ class OdbcDriver implements Dibi\Driver
* Commits statements in a transaction.
* @throws Dibi\DriverException
*/
public function commit(string $savepoint = null): void
public function commit(?string $savepoint = null): void
{
if (!odbc_commit($this->connection)) {
throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection));
@ -149,7 +149,7 @@ class OdbcDriver implements Dibi\Driver
* Rollback changes in a transaction.
* @throws Dibi\DriverException
*/
public function rollback(string $savepoint = null): void
public function rollback(?string $savepoint = null): void
{
if (!odbc_rollback($this->connection)) {
throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection));

View File

@ -148,7 +148,7 @@ class OracleDriver implements Dibi\Driver
/**
* Begins a transaction (if supported).
*/
public function begin(string $savepoint = null): void
public function begin(?string $savepoint = null): void
{
$this->autocommit = false;
}
@ -158,7 +158,7 @@ class OracleDriver implements Dibi\Driver
* Commits statements in a transaction.
* @throws Dibi\DriverException
*/
public function commit(string $savepoint = null): void
public function commit(?string $savepoint = null): void
{
if (!oci_commit($this->connection)) {
$err = oci_error($this->connection);
@ -173,7 +173,7 @@ class OracleDriver implements Dibi\Driver
* Rollback changes in a transaction.
* @throws Dibi\DriverException
*/
public function rollback(string $savepoint = null): void
public function rollback(?string $savepoint = null): void
{
if (!oci_rollback($this->connection)) {
$err = oci_error($this->connection);

View File

@ -144,7 +144,7 @@ class PdoDriver implements Dibi\Driver
* Begins a transaction (if supported).
* @throws Dibi\DriverException
*/
public function begin(string $savepoint = null): void
public function begin(?string $savepoint = null): void
{
if (!$this->connection->beginTransaction()) {
$err = $this->connection->errorInfo();
@ -157,7 +157,7 @@ class PdoDriver implements Dibi\Driver
* Commits statements in a transaction.
* @throws Dibi\DriverException
*/
public function commit(string $savepoint = null): void
public function commit(?string $savepoint = null): void
{
if (!$this->connection->commit()) {
$err = $this->connection->errorInfo();
@ -170,7 +170,7 @@ class PdoDriver implements Dibi\Driver
* Rollback changes in a transaction.
* @throws Dibi\DriverException
*/
public function rollback(string $savepoint = null): void
public function rollback(?string $savepoint = null): void
{
if (!$this->connection->rollBack()) {
$err = $this->connection->errorInfo();

View File

@ -133,7 +133,7 @@ class PostgreDriver implements Dibi\Driver
}
public static function createException(string $message, $code = null, string $sql = null): Dibi\DriverException
public static function createException(string $message, $code = null, ?string $sql = null): Dibi\DriverException
{
if ($code === null && preg_match('#^ERROR:\s+(\S+):\s*#', $message, $m)) {
$code = $m[1];
@ -189,7 +189,7 @@ class PostgreDriver implements Dibi\Driver
* Begins a transaction (if supported).
* @throws Dibi\DriverException
*/
public function begin(string $savepoint = null): void
public function begin(?string $savepoint = null): void
{
$this->query($savepoint ? "SAVEPOINT {$this->escapeIdentifier($savepoint)}" : 'START TRANSACTION');
}
@ -199,7 +199,7 @@ class PostgreDriver implements Dibi\Driver
* Commits statements in a transaction.
* @throws Dibi\DriverException
*/
public function commit(string $savepoint = null): void
public function commit(?string $savepoint = null): void
{
$this->query($savepoint ? "RELEASE SAVEPOINT {$this->escapeIdentifier($savepoint)}" : 'COMMIT');
}
@ -209,7 +209,7 @@ class PostgreDriver implements Dibi\Driver
* Rollback changes in a transaction.
* @throws Dibi\DriverException
*/
public function rollback(string $savepoint = null): void
public function rollback(?string $savepoint = null): void
{
$this->query($savepoint ? "ROLLBACK TO SAVEPOINT {$this->escapeIdentifier($savepoint)}" : 'ROLLBACK');
}

View File

@ -146,7 +146,7 @@ class SqliteDriver implements Dibi\Driver
* Begins a transaction (if supported).
* @throws Dibi\DriverException
*/
public function begin(string $savepoint = null): void
public function begin(?string $savepoint = null): void
{
$this->query($savepoint ? "SAVEPOINT $savepoint" : 'BEGIN');
}
@ -156,7 +156,7 @@ class SqliteDriver implements Dibi\Driver
* Commits statements in a transaction.
* @throws Dibi\DriverException
*/
public function commit(string $savepoint = null): void
public function commit(?string $savepoint = null): void
{
$this->query($savepoint ? "RELEASE SAVEPOINT $savepoint" : 'COMMIT');
}
@ -166,7 +166,7 @@ class SqliteDriver implements Dibi\Driver
* Rollback changes in a transaction.
* @throws Dibi\DriverException
*/
public function rollback(string $savepoint = null): void
public function rollback(?string $savepoint = null): void
{
$this->query($savepoint ? "ROLLBACK TO SAVEPOINT $savepoint" : 'ROLLBACK');
}

View File

@ -140,7 +140,7 @@ class SqlsrvDriver implements Dibi\Driver
* Begins a transaction (if supported).
* @throws Dibi\DriverException
*/
public function begin(string $savepoint = null): void
public function begin(?string $savepoint = null): void
{
sqlsrv_begin_transaction($this->connection);
}
@ -150,7 +150,7 @@ class SqlsrvDriver implements Dibi\Driver
* Commits statements in a transaction.
* @throws Dibi\DriverException
*/
public function commit(string $savepoint = null): void
public function commit(?string $savepoint = null): void
{
sqlsrv_commit($this->connection);
}
@ -160,7 +160,7 @@ class SqlsrvDriver implements Dibi\Driver
* Rollback changes in a transaction.
* @throws Dibi\DriverException
*/
public function rollback(string $savepoint = null): void
public function rollback(?string $savepoint = null): void
{
sqlsrv_rollback($this->connection);
}

View File

@ -53,7 +53,7 @@ class Event
public $source;
public function __construct(Connection $connection, int $type, string $sql = null)
public function __construct(Connection $connection, int $type, ?string $sql = null)
{
$this->connection = $connection;
$this->type = $type;

View File

@ -293,7 +293,7 @@ class Fluent implements IDataSource
* @return Result|int|null result set or number of affected rows
* @throws Exception
*/
public function execute(string $return = null)
public function execute(?string $return = null)
{
$res = $this->query($this->_export());
switch ($return) {
@ -334,7 +334,7 @@ class Fluent implements IDataSource
/**
* Fetches all records from table.
*/
public function fetchAll(int $offset = null, int $limit = null): array
public function fetchAll(?int $offset = null, ?int $limit = null): array
{
return $this->query($this->_export(null, ['%ofs %lmt', $offset, $limit]))->fetchAll();
}
@ -353,7 +353,7 @@ class Fluent implements IDataSource
/**
* Fetches all records from table like $key => $value pairs.
*/
public function fetchPairs(string $key = null, string $value = null): array
public function fetchPairs(?string $key = null, ?string $value = null): array
{
return $this->query($this->_export())->fetchPairs($key, $value);
}
@ -362,7 +362,7 @@ class Fluent implements IDataSource
/**
* Required by the IteratorAggregate interface.
*/
public function getIterator(int $offset = null, int $limit = null): ResultIterator
public function getIterator(?int $offset = null, ?int $limit = null): ResultIterator
{
return $this->query($this->_export(null, ['%ofs %lmt', $offset, $limit]))->getIterator();
}
@ -371,7 +371,7 @@ class Fluent implements IDataSource
/**
* Generates and prints SQL query or it's part.
*/
public function test(string $clause = null): bool
public function test(?string $clause = null): bool
{
return $this->connection->test($this->_export($clause));
}
@ -423,7 +423,7 @@ class Fluent implements IDataSource
/**
* Generates parameters for Translator.
*/
protected function _export(string $clause = null, array $args = []): array
protected function _export(?string $clause = null, array $args = []): array
{
if ($clause === null) {
$data = $this->clauses;

View File

@ -240,7 +240,7 @@ class Helpers
* Import SQL dump from file.
* @return int count of sql commands
*/
public static function loadFromFile(Connection $connection, string $file, callable $onProgress = null): int
public static function loadFromFile(Connection $connection, string $file, ?callable $onProgress = null): int
{
@set_time_limit(0); // intentionally @

View File

@ -29,7 +29,7 @@ class FileLogger
private $errorsOnly;
public function __construct(string $file, int $filter = null, bool $errorsOnly = false)
public function __construct(string $file, ?int $filter = null, bool $errorsOnly = false)
{
$this->file = $file;
$this->filter = $filter ?: Dibi\Event::QUERY;

View File

@ -36,7 +36,7 @@ class Column
private $info;
public function __construct(Dibi\Reflector $reflector = null, array $info)
public function __construct(?Dibi\Reflector $reflector, array $info)
{
$this->reflector = $reflector;
$this->info = $info;

View File

@ -33,7 +33,7 @@ class Database
private $tables;
public function __construct(Dibi\Reflector $reflector, string $name = null)
public function __construct(Dibi\Reflector $reflector, ?string $name = null)
{
$this->reflector = $reflector;
$this->name = $name;

View File

@ -204,7 +204,7 @@ class Result implements IDataSource
* Fetches all records from table.
* @return Row[]|array[]
*/
final public function fetchAll(int $offset = null, int $limit = null): array
final public function fetchAll(?int $offset = null, ?int $limit = null): array
{
$limit = $limit ?? -1;
$this->seek($offset ?: 0);
@ -377,7 +377,7 @@ class Result implements IDataSource
* Fetches all records from table like $key => $value pairs.
* @throws \InvalidArgumentException
*/
final public function fetchPairs(string $key = null, string $value = null): array
final public function fetchPairs(?string $key = null, ?string $value = null): array
{
$this->seek(0);
$row = $this->fetch();

View File

@ -33,7 +33,7 @@ class Row implements \ArrayAccess, \IteratorAggregate, \Countable
* Converts value to DateTime object.
* @return DateTime|string|null
*/
public function asDateTime(string $key, string $format = null)
public function asDateTime(string $key, ?string $format = null)
{
$time = $this[$key];
if (!$time instanceof DateTime) {

View File

@ -107,7 +107,7 @@ class dibi
* Retrieve active connection.
* @throws Dibi\Exception
*/
public static function getConnection(string $name = null): Dibi\Connection
public static function getConnection(?string $name = null): Dibi\Connection
{
if ($name === null) {
if (self::$connection === null) {

View File

@ -22,7 +22,7 @@ class Exception extends \Exception
/**
* @param int|string $code
*/
public function __construct(string $message = '', $code = 0, string $sql = null, \Throwable $previous = null)
public function __construct(string $message = '', $code = 0, ?string $sql = null, ?\Throwable $previous = null)
{
parent::__construct($message, 0, $previous);
$this->code = $code;
@ -93,7 +93,7 @@ class ProcedureException extends Exception
/**
* Construct the exception.
*/
public function __construct(string $message = '', int $code = 0, string $severity = '', string $sql = null)
public function __construct(string $message = '', int $code = 0, string $severity = '', ?string $sql = null)
{
parent::__construct($message, $code, $sql);
$this->severity = $severity;

View File

@ -51,19 +51,19 @@ interface Driver
* Begins a transaction (if supported).
* @throws DriverException
*/
function begin(string $savepoint = null): void;
function begin(?string $savepoint = null): void;
/**
* Commits statements in a transaction.
* @throws DriverException
*/
function commit(string $savepoint = null): void;
function commit(?string $savepoint = null): void;
/**
* Rollback changes in a transaction.
* @throws DriverException
*/
function rollback(string $savepoint = null): void;
function rollback(?string $savepoint = null): void;
/**
* Returns the connection resource.
@ -224,20 +224,20 @@ interface IConnection
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
* @throws Exception
*/
function getInsertId(string $sequence = null): int;
function getInsertId(?string $sequence = null): int;
/**
* Begins a transaction (if supported).
*/
function begin(string $savepoint = null): void;
function begin(?string $savepoint = null): void;
/**
* Commits statements in a transaction.
*/
function commit(string $savepoint = null): void;
function commit(?string $savepoint = null): void;
/**
* Rollback changes in a transaction.
*/
function rollback(string $savepoint = null): void;
function rollback(?string $savepoint = null): void;
}