From 7acef0c34b6b8b06fe84692ed80c72f2a3f212e3 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 9 Aug 2023 15:53:17 +0200 Subject: [PATCH] added property typehints --- src/Dibi/Bridges/Nette/DibiExtension22.php | 7 ++-- src/Dibi/Bridges/Tracy/Panel.php | 15 +++----- src/Dibi/Connection.php | 25 +++++-------- src/Dibi/DataSource.php | 39 ++++++-------------- src/Dibi/Drivers/FirebirdDriver.php | 6 ++-- src/Dibi/Drivers/FirebirdReflector.php | 3 +- src/Dibi/Drivers/MySqlReflector.php | 3 +- src/Dibi/Drivers/MySqliDriver.php | 9 ++--- src/Dibi/Drivers/MySqliResult.php | 7 ++-- src/Dibi/Drivers/NoDataResult.php | 3 +- src/Dibi/Drivers/OdbcDriver.php | 8 ++--- src/Dibi/Drivers/OdbcReflector.php | 3 +- src/Dibi/Drivers/OdbcResult.php | 4 +-- src/Dibi/Drivers/OracleDriver.php | 12 ++----- src/Dibi/Drivers/OracleReflector.php | 3 +- src/Dibi/Drivers/PdoDriver.php | 15 +++----- src/Dibi/Drivers/PdoResult.php | 7 ++-- src/Dibi/Drivers/PostgreDriver.php | 6 ++-- src/Dibi/Drivers/PostgreReflector.php | 7 ++-- src/Dibi/Drivers/SqliteDriver.php | 25 ++++++------- src/Dibi/Drivers/SqliteReflector.php | 3 +- src/Dibi/Drivers/SqliteResult.php | 3 +- src/Dibi/Drivers/SqlsrvDriver.php | 8 ++--- src/Dibi/Drivers/SqlsrvReflector.php | 3 +- src/Dibi/Event.php | 27 ++++---------- src/Dibi/Expression.php | 3 +- src/Dibi/Fluent.php | 42 ++++++++-------------- src/Dibi/Helpers.php | 5 ++- src/Dibi/Literal.php | 3 +- src/Dibi/Loggers/FileLogger.php | 12 +++---- src/Dibi/Reflection/Column.php | 6 ++-- src/Dibi/Reflection/Database.php | 13 +++---- src/Dibi/Reflection/ForeignKey.php | 5 ++- src/Dibi/Reflection/Index.php | 2 +- src/Dibi/Reflection/Result.php | 9 +++-- src/Dibi/Reflection/Table.php | 31 +++++++--------- src/Dibi/Result.php | 25 ++++++------- src/Dibi/ResultIterator.php | 11 ++---- src/Dibi/Translator.php | 41 ++++++--------------- src/Dibi/dibi.php | 22 ++++++------ src/Dibi/exceptions.php | 6 ++-- 41 files changed, 160 insertions(+), 327 deletions(-) diff --git a/src/Dibi/Bridges/Nette/DibiExtension22.php b/src/Dibi/Bridges/Nette/DibiExtension22.php index 906a5af6..a01e1e41 100644 --- a/src/Dibi/Bridges/Nette/DibiExtension22.php +++ b/src/Dibi/Bridges/Nette/DibiExtension22.php @@ -19,11 +19,8 @@ use Tracy; */ class DibiExtension22 extends Nette\DI\CompilerExtension { - /** @var bool|null */ - private $debugMode; - - /** @var bool|null */ - private $cliMode; + private ?bool $debugMode; + private ?bool $cliMode; public function __construct(?bool $debugMode = null, ?bool $cliMode = null) diff --git a/src/Dibi/Bridges/Tracy/Panel.php b/src/Dibi/Bridges/Tracy/Panel.php index 9e43df65..de1614ae 100644 --- a/src/Dibi/Bridges/Tracy/Panel.php +++ b/src/Dibi/Bridges/Tracy/Panel.php @@ -20,17 +20,10 @@ use Tracy; */ class Panel implements Tracy\IBarPanel { - /** @var int maximum SQL length */ - public static $maxLength = 1000; - - /** @var bool|string explain queries? */ - public $explain; - - /** @var int */ - public $filter; - - /** @var array */ - private $events = []; + public static int $maxLength = 1000; + public bool|string $explain; + public int $filter; + private array $events = []; public function __construct($explain = true, ?int $filter = null) diff --git a/src/Dibi/Connection.php b/src/Dibi/Connection.php index cf81edb3..e43b8e26 100644 --- a/src/Dibi/Connection.php +++ b/src/Dibi/Connection.php @@ -20,25 +20,16 @@ use Traversable; */ class Connection implements IConnection { - /** @var array of function (Event $event); Occurs after query is executed */ - public $onEvent = []; - - /** @var array Current connection configuration */ - private $config; + /** function (Event $event); Occurs after query is executed */ + public ?array $onEvent = []; + private array $config; /** @var string[] resultset formats */ - private $formats; - - /** @var Driver|null */ - private $driver; - - /** @var Translator|null */ - private $translator; - - /** @var HashMap Substitutes for identifiers */ - private $substitutes; - - private $transactionDepth = 0; + private array $formats; + private ?Driver $driver = null; + private ?Translator $translator = null; + private HashMap $substitutes; + private int $transactionDepth = 0; /** diff --git a/src/Dibi/DataSource.php b/src/Dibi/DataSource.php index c179dba0..1367aaf6 100644 --- a/src/Dibi/DataSource.php +++ b/src/Dibi/DataSource.php @@ -15,35 +15,16 @@ namespace Dibi; */ class DataSource implements IDataSource { - /** @var Connection */ - private $connection; - - /** @var string */ - private $sql; - - /** @var Result|null */ - private $result; - - /** @var int|null */ - private $count; - - /** @var int|null */ - private $totalCount; - - /** @var array */ - private $cols = []; - - /** @var array */ - private $sorting = []; - - /** @var array */ - private $conds = []; - - /** @var int|null */ - private $offset; - - /** @var int|null */ - private $limit; + private Connection $connection; + private string $sql; + private ?Result $result = null; + private ?int $count = null; + private ?int $totalCount = null; + private array $cols = []; + private array $sorting = []; + private array $conds = []; + private ?int $offset = null; + private ?int $limit = null; /** diff --git a/src/Dibi/Drivers/FirebirdDriver.php b/src/Dibi/Drivers/FirebirdDriver.php index d5bbd00b..962f9740 100644 --- a/src/Dibi/Drivers/FirebirdDriver.php +++ b/src/Dibi/Drivers/FirebirdDriver.php @@ -31,11 +31,9 @@ class FirebirdDriver implements Dibi\Driver /** @var resource */ private $connection; - /** @var resource|null */ + /** @var ?resource */ private $transaction; - - /** @var bool */ - private $inTransaction = false; + private bool $inTransaction = false; /** @throws Dibi\NotSupportedException */ diff --git a/src/Dibi/Drivers/FirebirdReflector.php b/src/Dibi/Drivers/FirebirdReflector.php index 6ba5ef47..4114f235 100644 --- a/src/Dibi/Drivers/FirebirdReflector.php +++ b/src/Dibi/Drivers/FirebirdReflector.php @@ -17,8 +17,7 @@ use Dibi; */ class FirebirdReflector implements Dibi\Reflector { - /** @var Dibi\Driver */ - private $driver; + private Dibi\Driver $driver; public function __construct(Dibi\Driver $driver) diff --git a/src/Dibi/Drivers/MySqlReflector.php b/src/Dibi/Drivers/MySqlReflector.php index 8d4017b3..dbd55828 100644 --- a/src/Dibi/Drivers/MySqlReflector.php +++ b/src/Dibi/Drivers/MySqlReflector.php @@ -18,8 +18,7 @@ use Dibi; */ class MySqlReflector implements Dibi\Reflector { - /** @var Dibi\Driver */ - private $driver; + private Dibi\Driver $driver; public function __construct(Dibi\Driver $driver) diff --git a/src/Dibi/Drivers/MySqliDriver.php b/src/Dibi/Drivers/MySqliDriver.php index 0f13349b..fd4e80df 100644 --- a/src/Dibi/Drivers/MySqliDriver.php +++ b/src/Dibi/Drivers/MySqliDriver.php @@ -33,16 +33,11 @@ use Dibi; class MySqliDriver implements Dibi\Driver { public const ERROR_ACCESS_DENIED = 1045; - public const ERROR_DUPLICATE_ENTRY = 1062; - public const ERROR_DATA_TRUNCATED = 1265; - /** @var \mysqli */ - private $connection; - - /** @var bool Is buffered (seekable and countable)? */ - private $buffered; + private \mysqli $connection; + private bool $buffered = false; /** @throws Dibi\NotSupportedException */ diff --git a/src/Dibi/Drivers/MySqliResult.php b/src/Dibi/Drivers/MySqliResult.php index 196dfd84..acdf6496 100644 --- a/src/Dibi/Drivers/MySqliResult.php +++ b/src/Dibi/Drivers/MySqliResult.php @@ -17,11 +17,8 @@ use Dibi; */ class MySqliResult implements Dibi\ResultDriver { - /** @var \mysqli_result */ - private $resultSet; - - /** @var bool Is buffered (seekable and countable)? */ - private $buffered; + private \mysqli_result $resultSet; + private bool $buffered; public function __construct(\mysqli_result $resultSet, bool $buffered) diff --git a/src/Dibi/Drivers/NoDataResult.php b/src/Dibi/Drivers/NoDataResult.php index ebc782cc..6172457d 100644 --- a/src/Dibi/Drivers/NoDataResult.php +++ b/src/Dibi/Drivers/NoDataResult.php @@ -17,8 +17,7 @@ use Dibi; */ class NoDataResult implements Dibi\ResultDriver { - /** @var int */ - private $rows; + private int $rows; public function __construct(int $rows) diff --git a/src/Dibi/Drivers/OdbcDriver.php b/src/Dibi/Drivers/OdbcDriver.php index 1ce9e8d7..60502836 100644 --- a/src/Dibi/Drivers/OdbcDriver.php +++ b/src/Dibi/Drivers/OdbcDriver.php @@ -27,12 +27,8 @@ class OdbcDriver implements Dibi\Driver { /** @var resource */ private $connection; - - /** @var int|null Affected rows */ - private $affectedRows; - - /** @var bool */ - private $microseconds = true; + private ?int $affectedRows; + private bool $microseconds = true; /** @throws Dibi\NotSupportedException */ diff --git a/src/Dibi/Drivers/OdbcReflector.php b/src/Dibi/Drivers/OdbcReflector.php index 3fd51560..3285fe03 100644 --- a/src/Dibi/Drivers/OdbcReflector.php +++ b/src/Dibi/Drivers/OdbcReflector.php @@ -17,8 +17,7 @@ use Dibi; */ class OdbcReflector implements Dibi\Reflector { - /** @var Dibi\Driver */ - private $driver; + private Dibi\Driver $driver; public function __construct(Dibi\Driver $driver) diff --git a/src/Dibi/Drivers/OdbcResult.php b/src/Dibi/Drivers/OdbcResult.php index e9c6c294..84fab2b8 100644 --- a/src/Dibi/Drivers/OdbcResult.php +++ b/src/Dibi/Drivers/OdbcResult.php @@ -19,9 +19,7 @@ class OdbcResult implements Dibi\ResultDriver { /** @var resource */ private $resultSet; - - /** @var int Cursor */ - private $row = 0; + private int $row = 0; /** diff --git a/src/Dibi/Drivers/OracleDriver.php b/src/Dibi/Drivers/OracleDriver.php index ca4fcefb..f431e1e1 100644 --- a/src/Dibi/Drivers/OracleDriver.php +++ b/src/Dibi/Drivers/OracleDriver.php @@ -29,15 +29,9 @@ class OracleDriver implements Dibi\Driver { /** @var resource */ private $connection; - - /** @var bool */ - private $autocommit = true; - - /** @var bool use native datetime format */ - private $nativeDate; - - /** @var int|null Number of affected rows */ - private $affectedRows; + private bool $autocommit = true; + private bool $nativeDate; + private ?int $affectedRows; /** @throws Dibi\NotSupportedException */ diff --git a/src/Dibi/Drivers/OracleReflector.php b/src/Dibi/Drivers/OracleReflector.php index d035e888..74c3db69 100644 --- a/src/Dibi/Drivers/OracleReflector.php +++ b/src/Dibi/Drivers/OracleReflector.php @@ -17,8 +17,7 @@ use Dibi; */ class OracleReflector implements Dibi\Reflector { - /** @var Dibi\Driver */ - private $driver; + private Dibi\Driver $driver; public function __construct(Dibi\Driver $driver) diff --git a/src/Dibi/Drivers/PdoDriver.php b/src/Dibi/Drivers/PdoDriver.php index 4b889a45..ca833798 100644 --- a/src/Dibi/Drivers/PdoDriver.php +++ b/src/Dibi/Drivers/PdoDriver.php @@ -27,17 +27,10 @@ use PDO; */ class PdoDriver implements Dibi\Driver { - /** @var PDO|null Connection resource */ - private $connection; - - /** @var int|null Affected rows */ - private $affectedRows; - - /** @var string */ - private $driverName; - - /** @var string */ - private $serverVersion = ''; + private ?PDO $connection; + private ?int $affectedRows; + private string $driverName; + private string $serverVersion = ''; /** @throws Dibi\NotSupportedException */ diff --git a/src/Dibi/Drivers/PdoResult.php b/src/Dibi/Drivers/PdoResult.php index 3cd7bd61..eb24b6fa 100644 --- a/src/Dibi/Drivers/PdoResult.php +++ b/src/Dibi/Drivers/PdoResult.php @@ -19,11 +19,8 @@ use PDO; */ class PdoResult implements Dibi\ResultDriver { - /** @var \PDOStatement|null */ - private $resultSet; - - /** @var string */ - private $driverName; + private ?\PDOStatement $resultSet; + private string $driverName; public function __construct(\PDOStatement $resultSet, string $driverName) diff --git a/src/Dibi/Drivers/PostgreDriver.php b/src/Dibi/Drivers/PostgreDriver.php index c1c3401d..6a3bd4e0 100644 --- a/src/Dibi/Drivers/PostgreDriver.php +++ b/src/Dibi/Drivers/PostgreDriver.php @@ -30,9 +30,7 @@ class PostgreDriver implements Dibi\Driver { /** @var resource|PgSql\Connection */ private $connection; - - /** @var int|null Affected rows */ - private $affectedRows; + private ?int $affectedRows; /** @throws Dibi\NotSupportedException */ @@ -138,7 +136,7 @@ class PostgreDriver implements Dibi\Driver $message = substr($message, strlen($m[0])); } - if ($code === '0A000' && strpos($message, 'truncate') !== false) { + if ($code === '0A000' && str_contains($message, 'truncate')) { return new Dibi\ForeignKeyConstraintViolationException($message, $code, $sql); } elseif ($code === '23502') { diff --git a/src/Dibi/Drivers/PostgreReflector.php b/src/Dibi/Drivers/PostgreReflector.php index 2893718f..6d08a17d 100644 --- a/src/Dibi/Drivers/PostgreReflector.php +++ b/src/Dibi/Drivers/PostgreReflector.php @@ -17,11 +17,8 @@ use Dibi; */ class PostgreReflector implements Dibi\Reflector { - /** @var Dibi\Driver */ - private $driver; - - /** @var string */ - private $version; + private Dibi\Driver $driver; + private string $version; public function __construct(Dibi\Driver $driver, string $version) diff --git a/src/Dibi/Drivers/SqliteDriver.php b/src/Dibi/Drivers/SqliteDriver.php index af54e3f3..c1b4b227 100644 --- a/src/Dibi/Drivers/SqliteDriver.php +++ b/src/Dibi/Drivers/SqliteDriver.php @@ -25,14 +25,9 @@ use SQLite3; */ class SqliteDriver implements Dibi\Driver { - /** @var SQLite3 */ - private $connection; - - /** @var string Date format */ - private $fmtDate; - - /** @var string Datetime format */ - private $fmtDateTime; + private SQLite3 $connection; + private string $fmtDate; + private string $fmtDateTime; /** @throws Dibi\NotSupportedException */ @@ -100,19 +95,19 @@ class SqliteDriver implements Dibi\Driver if ($code !== 19) { return new Dibi\DriverException($message, $code, $sql); - } elseif (strpos($message, 'must be unique') !== false - || strpos($message, 'is not unique') !== false - || strpos($message, 'UNIQUE constraint failed') !== false + } elseif (str_contains($message, 'must be unique') + || str_contains($message, 'is not unique') + || str_contains($message, 'UNIQUE constraint failed') ) { return new Dibi\UniqueConstraintViolationException($message, $code, $sql); - } elseif (strpos($message, 'may not be null') !== false - || strpos($message, 'NOT NULL constraint failed') !== false + } elseif (str_contains($message, 'may not be null') + || str_contains($message, 'NOT NULL constraint failed') ) { return new Dibi\NotNullConstraintViolationException($message, $code, $sql); - } elseif (strpos($message, 'foreign key constraint failed') !== false - || strpos($message, 'FOREIGN KEY constraint failed') !== false + } elseif (str_contains($message, 'foreign key constraint failed') + || str_contains($message, 'FOREIGN KEY constraint failed') ) { return new Dibi\ForeignKeyConstraintViolationException($message, $code, $sql); diff --git a/src/Dibi/Drivers/SqliteReflector.php b/src/Dibi/Drivers/SqliteReflector.php index b8dbbc7e..a85018e4 100644 --- a/src/Dibi/Drivers/SqliteReflector.php +++ b/src/Dibi/Drivers/SqliteReflector.php @@ -17,8 +17,7 @@ use Dibi; */ class SqliteReflector implements Dibi\Reflector { - /** @var Dibi\Driver */ - private $driver; + private Dibi\Driver $driver; public function __construct(Dibi\Driver $driver) diff --git a/src/Dibi/Drivers/SqliteResult.php b/src/Dibi/Drivers/SqliteResult.php index b39f7e51..218808b3 100644 --- a/src/Dibi/Drivers/SqliteResult.php +++ b/src/Dibi/Drivers/SqliteResult.php @@ -18,8 +18,7 @@ use Dibi\Helpers; */ class SqliteResult implements Dibi\ResultDriver { - /** @var \SQLite3Result */ - private $resultSet; + private \SQLite3Result $resultSet; public function __construct(\SQLite3Result $resultSet) diff --git a/src/Dibi/Drivers/SqlsrvDriver.php b/src/Dibi/Drivers/SqlsrvDriver.php index 888898c8..d741cc69 100644 --- a/src/Dibi/Drivers/SqlsrvDriver.php +++ b/src/Dibi/Drivers/SqlsrvDriver.php @@ -29,12 +29,8 @@ class SqlsrvDriver implements Dibi\Driver { /** @var resource */ private $connection; - - /** @var int|null Affected rows */ - private $affectedRows; - - /** @var string */ - private $version = ''; + private ?int $affectedRows; + private string $version = ''; /** @throws Dibi\NotSupportedException */ diff --git a/src/Dibi/Drivers/SqlsrvReflector.php b/src/Dibi/Drivers/SqlsrvReflector.php index 07a4f7e2..32fec929 100644 --- a/src/Dibi/Drivers/SqlsrvReflector.php +++ b/src/Dibi/Drivers/SqlsrvReflector.php @@ -17,8 +17,7 @@ use Dibi; */ class SqlsrvReflector implements Dibi\Reflector { - /** @var Dibi\Driver */ - private $driver; + private Dibi\Driver $driver; public function __construct(Dibi\Driver $driver) diff --git a/src/Dibi/Event.php b/src/Dibi/Event.php index 15317da4..d3cfc942 100644 --- a/src/Dibi/Event.php +++ b/src/Dibi/Event.php @@ -29,26 +29,13 @@ class Event TRANSACTION = 448, // BEGIN | COMMIT | ROLLBACK ALL = 1023; - /** @var Connection */ - public $connection; - - /** @var int */ - public $type; - - /** @var string */ - public $sql; - - /** @var Result|DriverException|null */ - public $result; - - /** @var float */ - public $time; - - /** @var int|null */ - public $count; - - /** @var array|null */ - public $source; + public Connection $connection; + public int $type; + public string $sql; + public Result|DriverException|null $result; + public float $time; + public ?int $count = null; + public ?array $source = null; public function __construct(Connection $connection, int $type, ?string $sql = null) diff --git a/src/Dibi/Expression.php b/src/Dibi/Expression.php index fba5d317..e5502991 100644 --- a/src/Dibi/Expression.php +++ b/src/Dibi/Expression.php @@ -15,8 +15,7 @@ namespace Dibi; */ class Expression { - /** @var array */ - private $values; + private array $values; public function __construct(...$values) diff --git a/src/Dibi/Fluent.php b/src/Dibi/Fluent.php index 56608575..7b4bc68f 100644 --- a/src/Dibi/Fluent.php +++ b/src/Dibi/Fluent.php @@ -47,8 +47,7 @@ class Fluent implements IDataSource { public const REMOVE = false; - /** @var array */ - public static $masks = [ + public static array $masks = [ 'SELECT' => ['SELECT', 'DISTINCT', 'FROM', 'WHERE', 'GROUP BY', 'HAVING', 'ORDER BY', 'LIMIT', 'OFFSET', ], 'UPDATE' => ['UPDATE', 'SET', 'WHERE', 'ORDER BY', 'LIMIT'], @@ -56,8 +55,8 @@ class Fluent implements IDataSource 'DELETE' => ['DELETE', 'FROM', 'USING', 'WHERE', 'ORDER BY', 'LIMIT'], ]; - /** @var array default modifiers for arrays */ - public static $modifiers = [ + /** default modifiers for arrays */ + public static array $modifiers = [ 'SELECT' => '%n', 'FROM' => '%n', 'IN' => '%in', @@ -69,8 +68,8 @@ class Fluent implements IDataSource 'GROUP BY' => '%by', ]; - /** @var array clauses separators */ - public static $separators = [ + /** clauses separators */ + public static array $separators = [ 'SELECT' => ',', 'FROM' => ',', 'WHERE' => 'AND', @@ -84,41 +83,30 @@ class Fluent implements IDataSource 'INTO' => false, ]; - /** @var array clauses */ - public static $clauseSwitches = [ + /** clauses */ + public static array $clauseSwitches = [ 'JOIN' => 'FROM', 'INNER JOIN' => 'FROM', 'LEFT JOIN' => 'FROM', 'RIGHT JOIN' => 'FROM', ]; - /** @var Connection */ - private $connection; - - /** @var array */ - private $setups = []; - - /** @var string|null */ - private $command; - - /** @var array */ - private $clauses = []; - - /** @var array */ - private $flags = []; - - /** @var array|null */ + private Connection $connection; + private array $setups = []; + private ?string $command = null; + private array $clauses = []; + private array $flags = []; private $cursor; - /** @var HashMap normalized clauses */ - private static $normalizer; + /** normalized clauses */ + private static HashMap $normalizer; public function __construct(Connection $connection) { $this->connection = $connection; - if (self::$normalizer === null) { + if (!isset(self::$normalizer)) { self::$normalizer = new HashMap([self::class, '_formatClause']); } } diff --git a/src/Dibi/Helpers.php b/src/Dibi/Helpers.php index d9f5607a..af59f3c3 100644 --- a/src/Dibi/Helpers.php +++ b/src/Dibi/Helpers.php @@ -12,8 +12,7 @@ namespace Dibi; class Helpers { - /** @var HashMap */ - private static $types; + private static HashMap $types; /** @@ -209,7 +208,7 @@ class Helpers /** @internal */ public static function getTypeCache(): HashMap { - if (self::$types === null) { + if (!isset(self::$types)) { self::$types = new HashMap([self::class, 'detectType']); } diff --git a/src/Dibi/Literal.php b/src/Dibi/Literal.php index 2fb74140..ca395859 100644 --- a/src/Dibi/Literal.php +++ b/src/Dibi/Literal.php @@ -15,8 +15,7 @@ namespace Dibi; */ class Literal { - /** @var string */ - private $value; + private string $value; public function __construct($value) diff --git a/src/Dibi/Loggers/FileLogger.php b/src/Dibi/Loggers/FileLogger.php index 723d9537..3a71fc88 100644 --- a/src/Dibi/Loggers/FileLogger.php +++ b/src/Dibi/Loggers/FileLogger.php @@ -17,14 +17,10 @@ use Dibi; */ class FileLogger { - /** @var string Name of the file where SQL errors should be logged */ - public $file; - - /** @var int */ - public $filter; - - /** @var bool */ - private $errorsOnly; + /** Name of the file where SQL errors should be logged */ + public string $file; + public int $filter; + private bool $errorsOnly; public function __construct(string $file, ?int $filter = null, bool $errorsOnly = false) diff --git a/src/Dibi/Reflection/Column.php b/src/Dibi/Reflection/Column.php index 9be29598..ad1793dd 100644 --- a/src/Dibi/Reflection/Column.php +++ b/src/Dibi/Reflection/Column.php @@ -27,11 +27,11 @@ use Dibi; */ class Column { - /** @var Dibi\Reflector|null when created by Result */ - private $reflector; + /** when created by Result */ + private ?Dibi\Reflector $reflector; /** @var array (name, nativetype, [table], [fullname], [size], [nullable], [default], [autoincrement], [vendor]) */ - private $info; + private array $info; public function __construct(?Dibi\Reflector $reflector, array $info) diff --git a/src/Dibi/Reflection/Database.php b/src/Dibi/Reflection/Database.php index 67beb1d2..a6c42efd 100644 --- a/src/Dibi/Reflection/Database.php +++ b/src/Dibi/Reflection/Database.php @@ -21,14 +21,11 @@ use Dibi; */ class Database { - /** @var Dibi\Reflector */ - private $reflector; + private Dibi\Reflector $reflector; + private ?string $name; - /** @var string|null */ - private $name; - - /** @var Table[]|null */ - private $tables; + /** @var Table[] */ + private array $tables; public function __construct(Dibi\Reflector $reflector, ?string $name = null) @@ -87,7 +84,7 @@ class Database protected function init(): void { - if ($this->tables === null) { + if (!isset($this->tables)) { $this->tables = []; foreach ($this->reflector->getTables() as $info) { $this->tables[strtolower($info['name'])] = new Table($this->reflector, $info); diff --git a/src/Dibi/Reflection/ForeignKey.php b/src/Dibi/Reflection/ForeignKey.php index 20ee6a4f..492a66f3 100644 --- a/src/Dibi/Reflection/ForeignKey.php +++ b/src/Dibi/Reflection/ForeignKey.php @@ -19,11 +19,10 @@ namespace Dibi\Reflection; */ class ForeignKey { - /** @var string */ - private $name; + private string $name; /** @var array of [local, foreign, onDelete, onUpdate] */ - private $references; + private array $references; public function __construct(string $name, array $references) diff --git a/src/Dibi/Reflection/Index.php b/src/Dibi/Reflection/Index.php index 2c23214c..13fe1df7 100644 --- a/src/Dibi/Reflection/Index.php +++ b/src/Dibi/Reflection/Index.php @@ -22,7 +22,7 @@ namespace Dibi\Reflection; class Index { /** @var array (name, columns, [unique], [primary]) */ - private $info; + private array $info; public function __construct(array $info) diff --git a/src/Dibi/Reflection/Result.php b/src/Dibi/Reflection/Result.php index 41b364fe..3cd1dd93 100644 --- a/src/Dibi/Reflection/Result.php +++ b/src/Dibi/Reflection/Result.php @@ -20,14 +20,13 @@ use Dibi; */ class Result { - /** @var Dibi\ResultDriver */ - private $driver; + private Dibi\ResultDriver $driver; /** @var Column[]|null */ - private $columns; + private ?array $columns; /** @var Column[]|null */ - private $names; + private ?array $names; public function __construct(Dibi\ResultDriver $driver) @@ -79,7 +78,7 @@ class Result protected function initColumns(): void { - if ($this->columns === null) { + if (!isset($this->columns)) { $this->columns = []; $reflector = $this->driver instanceof Dibi\Reflector ? $this->driver diff --git a/src/Dibi/Reflection/Table.php b/src/Dibi/Reflection/Table.php index e8b06435..b03d4807 100644 --- a/src/Dibi/Reflection/Table.php +++ b/src/Dibi/Reflection/Table.php @@ -25,26 +25,19 @@ use Dibi; */ class Table { - /** @var Dibi\Reflector */ - private $reflector; + private Dibi\Reflector $reflector; + private string $name; + private bool $view; - /** @var string */ - private $name; + /** @var Column[] */ + private array $columns; - /** @var bool */ - private $view; + /** @var ForeignKey[] */ + private array $foreignKeys; - /** @var Column[]|null */ - private $columns; - - /** @var ForeignKey[]|null */ - private $foreignKeys; - - /** @var Index[]|null */ - private $indexes; - - /** @var Index|null */ - private $primaryKey; + /** @var Index[] */ + private array $indexes; + private ?Index $primaryKey; public function __construct(Dibi\Reflector $reflector, array $info) @@ -133,7 +126,7 @@ class Table protected function initColumns(): void { - if ($this->columns === null) { + if (!isset($this->columns)) { $this->columns = []; foreach ($this->reflector->getColumns($this->name) as $info) { $this->columns[strtolower($info['name'])] = new Column($this->reflector, $info); @@ -144,7 +137,7 @@ class Table protected function initIndexes(): void { - if ($this->indexes === null) { + if (!isset($this->indexes)) { $this->initColumns(); $this->indexes = []; foreach ($this->reflector->getIndexes($this->name) as $info) { diff --git a/src/Dibi/Result.php b/src/Dibi/Result.php index 3b2d9812..502a7a41 100644 --- a/src/Dibi/Result.php +++ b/src/Dibi/Result.php @@ -17,26 +17,21 @@ namespace Dibi; */ class Result implements IDataSource { - /** @var ResultDriver|null */ - private $driver; + private ?ResultDriver $driver; - /** @var array Translate table */ - private $types = []; + /** Translate table */ + private array $types = []; + private ?Reflection\Result $meta; - /** @var Reflection\Result|null */ - private $meta; + /** Already fetched? Used for allowance for first seek(0) */ + private bool $fetched = false; - /** @var bool Already fetched? Used for allowance for first seek(0) */ - private $fetched = false; - - /** @var string|null returned object class */ - private $rowClass = Row::class; + /** returned object class */ + private ?string $rowClass = Row::class; /** @var callable|null returned object factory */ private $rowFactory; - - /** @var array format */ - private $formats = []; + private array $formats = []; public function __construct(ResultDriver $driver, bool $normalize = true) @@ -589,7 +584,7 @@ class Result implements IDataSource */ public function getInfo(): Reflection\Result { - if ($this->meta === null) { + if (!isset($this->meta)) { $this->meta = new Reflection\Result($this->getResultDriver()); } diff --git a/src/Dibi/ResultIterator.php b/src/Dibi/ResultIterator.php index d33b9f59..a6c609b7 100644 --- a/src/Dibi/ResultIterator.php +++ b/src/Dibi/ResultIterator.php @@ -15,14 +15,9 @@ namespace Dibi; */ class ResultIterator implements \Iterator, \Countable { - /** @var Result */ - private $result; - - /** @var mixed */ - private $row; - - /** @var int */ - private $pointer = 0; + private Result $result; + private mixed $row; + private int $pointer = 0; public function __construct(Result $result) diff --git a/src/Dibi/Translator.php b/src/Dibi/Translator.php index e99aa945..213cb83e 100644 --- a/src/Dibi/Translator.php +++ b/src/Dibi/Translator.php @@ -15,38 +15,19 @@ namespace Dibi; */ final class Translator { - /** @var Connection */ - private $connection; - - /** @var Driver */ - private $driver; - - /** @var int */ - private $cursor = 0; - - /** @var array */ - private $args; + private Connection $connection; + private Driver $driver; + private int $cursor = 0; + private array $args; /** @var string[] */ - private $errors; - - /** @var bool */ - private $comment = false; - - /** @var int */ - private $ifLevel = 0; - - /** @var int */ - private $ifLevelStart = 0; - - /** @var int|null */ - private $limit; - - /** @var int|null */ - private $offset; - - /** @var HashMap */ - private $identifiers; + private array $errors; + private bool $comment = false; + private int $ifLevel = 0; + private int $ifLevelStart = 0; + private ?int $limit = null; + private ?int $offset = null; + private HashMap $identifiers; public function __construct(Connection $connection) diff --git a/src/Dibi/dibi.php b/src/Dibi/dibi.php index 37aaaf6a..87cb4f8b 100644 --- a/src/Dibi/dibi.php +++ b/src/Dibi/dibi.php @@ -49,23 +49,23 @@ class dibi ASC = 'ASC', DESC = 'DESC'; - /** @var string|null Last SQL command @see dibi::query() */ - public static $sql; + /** Last SQL command @see dibi::query() */ + public static ?string $sql = null; - /** @var float|null Elapsed time for last query */ - public static $elapsedTime; + /** Elapsed time for last query */ + public static ?float $elapsedTime = null; - /** @var float Elapsed time for all queries */ - public static $totalTime; + /** Elapsed time for all queries */ + public static float $totalTime = 0; - /** @var int Number or queries */ - public static $numOfQueries = 0; + /** Number or queries */ + public static int $numOfQueries = 0; /** @var Dibi\Connection[] Connection registry storage for Dibi\Connection objects */ - private static $registry = []; + private static array $registry = []; - /** @var Dibi\Connection Current connection */ - private static $connection; + /** Current connection */ + private static Dibi\Connection $connection; /** diff --git a/src/Dibi/exceptions.php b/src/Dibi/exceptions.php index 4d705790..5841db52 100644 --- a/src/Dibi/exceptions.php +++ b/src/Dibi/exceptions.php @@ -15,8 +15,7 @@ namespace Dibi; */ class Exception extends \Exception { - /** @var string|null */ - private $sql; + private ?string $sql; /** @@ -86,8 +85,7 @@ class NotSupportedException extends Exception */ class ProcedureException extends Exception { - /** @var string */ - protected $severity; + protected string $severity; /**