1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-07 14:46:50 +02:00

added property typehints

This commit is contained in:
David Grudl
2021-03-01 19:17:16 +01:00
parent 76b8ed2108
commit 0575f9ea17
46 changed files with 165 additions and 265 deletions

View File

@@ -19,11 +19,9 @@ use Tracy;
*/
class DibiExtension22 extends Nette\DI\CompilerExtension
{
/** @var bool|null */
private $debugMode;
private ?bool $debugMode;
/** @var bool|null */
private $cliMode;
private ?bool $cliMode;
public function __construct(?bool $debugMode = null, ?bool $cliMode = null)

View File

@@ -22,17 +22,14 @@ class Panel implements Tracy\IBarPanel
{
use Dibi\Strict;
/** @var int maximum SQL length */
public static $maxLength = 1000;
/** maximum SQL length */
public static int $maxLength = 1000;
/** @var bool|string explain queries? */
public $explain;
public bool|string $explain;
/** @var int */
public $filter;
public int $filter;
/** @var array */
private $events = [];
private array $events = [];
public function __construct($explain = true, ?int $filter = null)

View File

@@ -22,25 +22,22 @@ class Connection implements IConnection
{
use Strict;
/** @var array of function (Event $event); Occurs after query is executed */
public $onEvent = [];
/** function (Event $event); Occurs after query is executed */
public ?array $onEvent = [];
/** @var array Current connection configuration */
private $config;
/** Current connection configuration */
private array $config;
/** @var string[] resultset formats */
private $formats;
private array $formats;
/** @var Driver|null */
private $driver;
private ?Driver $driver = null;
/** @var Translator|null */
private $translator;
private ?Translator $translator = null;
/** @var HashMap Substitutes for identifiers */
private $substitutes;
private HashMap $substitutes;
private $transactionDepth = 0;
private int $transactionDepth = 0;
/**

View File

@@ -17,35 +17,25 @@ class DataSource implements IDataSource
{
use Strict;
/** @var Connection */
private $connection;
private Connection $connection;
/** @var string */
private $sql;
private string $sql;
/** @var Result|null */
private $result;
private ?Result $result = null;
/** @var int|null */
private $count;
private ?int $count = null;
/** @var int|null */
private $totalCount;
private ?int $totalCount = null;
/** @var array */
private $cols = [];
private array $cols = [];
/** @var array */
private $sorting = [];
private array $sorting = [];
/** @var array */
private $conds = [];
private array $conds = [];
/** @var int|null */
private $offset;
private ?int $offset = null;
/** @var int|null */
private $limit;
private ?int $limit = null;
/**

View File

@@ -33,11 +33,10 @@ 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 */

View File

@@ -19,8 +19,7 @@ class FirebirdReflector implements Dibi\Reflector
{
use Dibi\Strict;
/** @var Dibi\Driver */
private $driver;
private Dibi\Driver $driver;
public function __construct(Dibi\Driver $driver)

View File

@@ -23,8 +23,7 @@ class FirebirdResult implements Dibi\ResultDriver
/** @var resource */
private $resultSet;
/** @var bool */
private $autoFree = true;
private bool $autoFree = true;
/**

View File

@@ -20,8 +20,7 @@ class MySqlReflector implements Dibi\Reflector
{
use Dibi\Strict;
/** @var Dibi\Driver */
private $driver;
private Dibi\Driver $driver;
public function __construct(Dibi\Driver $driver)

View File

@@ -40,11 +40,10 @@ class MySqliDriver implements Dibi\Driver
public const ERROR_DATA_TRUNCATED = 1265;
/** @var \mysqli */
private $connection;
private \mysqli $connection;
/** @var bool Is buffered (seekable and countable)? */
private $buffered;
/** Is buffered (seekable and countable)? */
private bool $buffered = false;
/** @throws Dibi\NotSupportedException */

View File

@@ -19,14 +19,12 @@ class MySqliResult implements Dibi\ResultDriver
{
use Dibi\Strict;
/** @var \mysqli_result */
private $resultSet;
private \mysqli_result $resultSet;
/** @var bool */
private $autoFree = true;
private bool $autoFree = true;
/** @var bool Is buffered (seekable and countable)? */
private $buffered;
/** Is buffered (seekable and countable)? */
private bool $buffered;
public function __construct(\mysqli_result $resultSet, bool $buffered)

View File

@@ -19,8 +19,7 @@ class NoDataResult implements Dibi\ResultDriver
{
use Dibi\Strict;
/** @var int */
private $rows;
private int $rows;
public function __construct(int $rows)

View File

@@ -30,11 +30,9 @@ class OdbcDriver implements Dibi\Driver
/** @var resource */
private $connection;
/** @var int|null Affected rows */
private $affectedRows;
private ?int $affectedRows;
/** @var bool */
private $microseconds = true;
private bool $microseconds = true;
/** @throws Dibi\NotSupportedException */

View File

@@ -19,8 +19,7 @@ class OdbcReflector implements Dibi\Reflector
{
use Dibi\Strict;
/** @var Dibi\Driver */
private $driver;
private Dibi\Driver $driver;
public function __construct(Dibi\Driver $driver)

View File

@@ -22,11 +22,9 @@ class OdbcResult implements Dibi\ResultDriver
/** @var resource */
private $resultSet;
/** @var bool */
private $autoFree = true;
private bool $autoFree = true;
/** @var int Cursor */
private $row = 0;
private int $row = 0;
/**

View File

@@ -32,14 +32,12 @@ class OracleDriver implements Dibi\Driver
/** @var resource */
private $connection;
/** @var bool */
private $autocommit = true;
private bool $autocommit = true;
/** @var bool use native datetime format */
private $nativeDate;
/** use native datetime format */
private bool $nativeDate;
/** @var int|null Number of affected rows */
private $affectedRows;
private ?int $affectedRows;
/** @throws Dibi\NotSupportedException */

View File

@@ -19,8 +19,7 @@ class OracleReflector implements Dibi\Reflector
{
use Dibi\Strict;
/** @var Dibi\Driver */
private $driver;
private Dibi\Driver $driver;
public function __construct(Dibi\Driver $driver)

View File

@@ -22,8 +22,7 @@ class OracleResult implements Dibi\ResultDriver
/** @var resource */
private $resultSet;
/** @var bool */
private $autoFree = true;
private bool $autoFree = true;
/**

View File

@@ -29,17 +29,13 @@ class PdoDriver implements Dibi\Driver
{
use Dibi\Strict;
/** @var PDO|null Connection resource */
private $connection;
private ?PDO $connection;
/** @var int|null Affected rows */
private $affectedRows;
private ?int $affectedRows;
/** @var string */
private $driverName;
private string $driverName;
/** @var string */
private $serverVersion = '';
private string $serverVersion = '';
/** @throws Dibi\NotSupportedException */

View File

@@ -21,11 +21,9 @@ class PdoResult implements Dibi\ResultDriver
{
use Dibi\Strict;
/** @var \PDOStatement|null */
private $resultSet;
private ?\PDOStatement $resultSet;
/** @var string */
private $driverName;
private string $driverName;
public function __construct(\PDOStatement $resultSet, string $driverName)

View File

@@ -33,8 +33,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 */

View File

@@ -19,11 +19,9 @@ class PostgreReflector implements Dibi\Reflector
{
use Dibi\Strict;
/** @var Dibi\Driver */
private $driver;
private Dibi\Driver $driver;
/** @var string */
private $version;
private string $version;
public function __construct(Dibi\Driver $driver, string $version)

View File

@@ -24,8 +24,7 @@ class PostgreResult implements Dibi\ResultDriver
/** @var resource|PgSql\Result */
private $resultSet;
/** @var bool */
private $autoFree = true;
private bool $autoFree = true;
/**

View File

@@ -27,14 +27,11 @@ class SqliteDriver implements Dibi\Driver
{
use Dibi\Strict;
/** @var SQLite3 */
private $connection;
private SQLite3 $connection;
/** @var string Date format */
private $fmtDate;
private string $fmtDate;
/** @var string Datetime format */
private $fmtDateTime;
private string $fmtDateTime;
/** @throws Dibi\NotSupportedException */

View File

@@ -19,8 +19,7 @@ class SqliteReflector implements Dibi\Reflector
{
use Dibi\Strict;
/** @var Dibi\Driver */
private $driver;
private Dibi\Driver $driver;
public function __construct(Dibi\Driver $driver)

View File

@@ -20,11 +20,9 @@ class SqliteResult implements Dibi\ResultDriver
{
use Dibi\Strict;
/** @var \SQLite3Result */
private $resultSet;
private \SQLite3Result $resultSet;
/** @var bool */
private $autoFree = true;
private bool $autoFree = true;
public function __construct(\SQLite3Result $resultSet)

View File

@@ -32,11 +32,9 @@ class SqlsrvDriver implements Dibi\Driver
/** @var resource */
private $connection;
/** @var int|null Affected rows */
private $affectedRows;
private ?int $affectedRows;
/** @var string */
private $version = '';
private string $version = '';
/** @throws Dibi\NotSupportedException */

View File

@@ -19,8 +19,7 @@ class SqlsrvReflector implements Dibi\Reflector
{
use Dibi\Strict;
/** @var Dibi\Driver */
private $driver;
private Dibi\Driver $driver;
public function __construct(Dibi\Driver $driver)

View File

@@ -22,8 +22,7 @@ class SqlsrvResult implements Dibi\ResultDriver
/** @var resource */
private $resultSet;
/** @var bool */
private $autoFree = true;
private bool $autoFree = true;
/**

View File

@@ -31,26 +31,19 @@ class Event
TRANSACTION = 448, // BEGIN | COMMIT | ROLLBACK
ALL = 1023;
/** @var Connection */
public $connection;
public Connection $connection;
/** @var int */
public $type;
public int $type;
/** @var string */
public $sql;
public string $sql;
/** @var Result|DriverException|null */
public $result;
public Result|DriverException|null $result;
/** @var float */
public $time;
public float $time;
/** @var int|null */
public $count;
public ?int $count = null;
/** @var array|null */
public $source;
public ?array $source = null;
public function __construct(Connection $connection, int $type, ?string $sql = null)

View File

@@ -17,8 +17,7 @@ class Expression
{
use Strict;
/** @var array */
private $values;
private array $values;
public function __construct(...$values)

View File

@@ -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,35 @@ 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;
private Connection $connection;
/** @var array */
private $setups = [];
private array $setups = [];
/** @var string|null */
private $command;
private ?string $command = null;
/** @var array */
private $clauses = [];
private array $clauses = [];
/** @var array */
private $flags = [];
private array $flags = [];
/** @var array|null */
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']);
}
}

View File

@@ -14,8 +14,7 @@ class Helpers
{
use Strict;
/** @var HashMap */
private static $types;
private static HashMap $types;
/**
@@ -211,7 +210,7 @@ class Helpers
/** @internal */
public static function getTypeCache(): HashMap
{
if (self::$types === null) {
if (!isset(self::$types)) {
self::$types = new HashMap([self::class, 'detectType']);
}

View File

@@ -17,8 +17,7 @@ class Literal
{
use Strict;
/** @var string */
private $value;
private string $value;
public function __construct($value)

View File

@@ -19,14 +19,12 @@ class FileLogger
{
use Dibi\Strict;
/** @var string Name of the file where SQL errors should be logged */
public $file;
/** Name of the file where SQL errors should be logged */
public string $file;
/** @var int */
public $filter;
public int $filter;
/** @var bool */
private $errorsOnly;
private bool $errorsOnly;
public function __construct(string $file, ?int $filter = null, bool $errorsOnly = false)

View File

@@ -29,11 +29,11 @@ class Column
{
use Dibi\Strict;
/** @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)

View File

@@ -23,14 +23,12 @@ class Database
{
use Dibi\Strict;
/** @var Dibi\Reflector */
private $reflector;
private Dibi\Reflector $reflector;
/** @var string|null */
private $name;
private ?string $name;
/** @var Table[]|null */
private $tables;
/** @var Table[] */
private array $tables;
public function __construct(Dibi\Reflector $reflector, ?string $name = null)
@@ -89,7 +87,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);

View File

@@ -22,11 +22,10 @@ class ForeignKey
{
use Dibi\Strict;
/** @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)

View File

@@ -25,7 +25,7 @@ class Index
use Dibi\Strict;
/** @var array (name, columns, [unique], [primary]) */
private $info;
private array $info;
public function __construct(array $info)

View File

@@ -22,14 +22,13 @@ class Result
{
use Dibi\Strict;
/** @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)
@@ -81,7 +80,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

View File

@@ -27,26 +27,22 @@ class Table
{
use Dibi\Strict;
/** @var Dibi\Reflector */
private $reflector;
private Dibi\Reflector $reflector;
/** @var string */
private $name;
private string $name;
/** @var bool */
private $view;
private bool $view;
/** @var Column[]|null */
private $columns;
/** @var Column[] */
private array $columns;
/** @var ForeignKey[]|null */
private $foreignKeys;
/** @var ForeignKey[] */
private array $foreignKeys;
/** @var Index[]|null */
private $indexes;
/** @var Index[] */
private array $indexes;
/** @var Index|null */
private $primaryKey;
private ?Index $primaryKey;
public function __construct(Dibi\Reflector $reflector, array $info)
@@ -135,7 +131,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);
@@ -146,7 +142,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) {

View File

@@ -19,26 +19,23 @@ class Result implements IDataSource
{
use Strict;
/** @var ResultDriver|null */
private $driver;
private ?ResultDriver $driver;
/** @var array Translate table */
private $types = [];
/** Translate table */
private array $types = [];
/** @var Reflection\Result|null */
private $meta;
private ?Reflection\Result $meta;
/** @var bool Already fetched? Used for allowance for first seek(0) */
private $fetched = false;
/** Already fetched? Used for allowance for first seek(0) */
private bool $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)
@@ -591,7 +588,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());
}

View File

@@ -17,14 +17,11 @@ class ResultIterator implements \Iterator, \Countable
{
use Strict;
/** @var Result */
private $result;
private Result $result;
/** @var mixed */
private $row;
private mixed $row;
/** @var int */
private $pointer = 0;
private int $pointer = 0;
public function __construct(Result $result)

View File

@@ -20,7 +20,7 @@ use ReflectionProperty;
trait Strict
{
/** @var array [method => [type => callback]] */
private static $extMethods;
private static array $extMethods;
/**

View File

@@ -17,38 +17,28 @@ final class Translator
{
use Strict;
/** @var Connection */
private $connection;
private Connection $connection;
/** @var Driver */
private $driver;
private Driver $driver;
/** @var int */
private $cursor = 0;
private int $cursor = 0;
/** @var array */
private $args;
private array $args;
/** @var string[] */
private $errors;
private array $errors;
/** @var bool */
private $comment = false;
private bool $comment = false;
/** @var int */
private $ifLevel = 0;
private int $ifLevel = 0;
/** @var int */
private $ifLevelStart = 0;
private int $ifLevelStart = 0;
/** @var int|null */
private $limit;
private ?int $limit = null;
/** @var int|null */
private $offset;
private ?int $offset = null;
/** @var HashMap */
private $identifiers;
private HashMap $identifiers;
public function __construct(Connection $connection)

View File

@@ -51,23 +51,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;
/**

View File

@@ -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;
/**