Skip to content

Commit

Permalink
added property typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Aug 9, 2023
1 parent b01d97a commit 7acef0c
Show file tree
Hide file tree
Showing 41 changed files with 160 additions and 327 deletions.
7 changes: 2 additions & 5 deletions src/Dibi/Bridges/Nette/DibiExtension22.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@
*/
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)
Expand Down
15 changes: 4 additions & 11 deletions src/Dibi/Bridges/Tracy/Panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,10 @@
*/
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)
Expand Down
25 changes: 8 additions & 17 deletions src/Dibi/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,16 @@
*/
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;


/**
Expand Down
39 changes: 10 additions & 29 deletions src/Dibi/DataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,16 @@
*/
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;


/**
Expand Down
6 changes: 2 additions & 4 deletions src/Dibi/Drivers/FirebirdDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
3 changes: 1 addition & 2 deletions src/Dibi/Drivers/FirebirdReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
*/
class FirebirdReflector implements Dibi\Reflector
{
/** @var Dibi\Driver */
private $driver;
private Dibi\Driver $driver;


public function __construct(Dibi\Driver $driver)
Expand Down
3 changes: 1 addition & 2 deletions src/Dibi/Drivers/MySqlReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
*/
class MySqlReflector implements Dibi\Reflector
{
/** @var Dibi\Driver */
private $driver;
private Dibi\Driver $driver;


public function __construct(Dibi\Driver $driver)
Expand Down
9 changes: 2 additions & 7 deletions src/Dibi/Drivers/MySqliDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,11 @@
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 */
Expand Down
7 changes: 2 additions & 5 deletions src/Dibi/Drivers/MySqliResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
*/
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)
Expand Down
3 changes: 1 addition & 2 deletions src/Dibi/Drivers/NoDataResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
*/
class NoDataResult implements Dibi\ResultDriver
{
/** @var int */
private $rows;
private int $rows;


public function __construct(int $rows)
Expand Down
8 changes: 2 additions & 6 deletions src/Dibi/Drivers/OdbcDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
3 changes: 1 addition & 2 deletions src/Dibi/Drivers/OdbcReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
*/
class OdbcReflector implements Dibi\Reflector
{
/** @var Dibi\Driver */
private $driver;
private Dibi\Driver $driver;


public function __construct(Dibi\Driver $driver)
Expand Down
4 changes: 1 addition & 3 deletions src/Dibi/Drivers/OdbcResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ class OdbcResult implements Dibi\ResultDriver
{
/** @var resource */
private $resultSet;

/** @var int Cursor */
private $row = 0;
private int $row = 0;


/**
Expand Down
12 changes: 3 additions & 9 deletions src/Dibi/Drivers/OracleDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
3 changes: 1 addition & 2 deletions src/Dibi/Drivers/OracleReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
*/
class OracleReflector implements Dibi\Reflector
{
/** @var Dibi\Driver */
private $driver;
private Dibi\Driver $driver;


public function __construct(Dibi\Driver $driver)
Expand Down
15 changes: 4 additions & 11 deletions src/Dibi/Drivers/PdoDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,10 @@
*/
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 */
Expand Down
7 changes: 2 additions & 5 deletions src/Dibi/Drivers/PdoResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@
*/
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)
Expand Down
6 changes: 2 additions & 4 deletions src/Dibi/Drivers/PostgreDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -138,7 +136,7 @@ public static function createException(string $message, $code = null, ?string $s
$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') {
Expand Down
7 changes: 2 additions & 5 deletions src/Dibi/Drivers/PostgreReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
*/
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)
Expand Down
25 changes: 10 additions & 15 deletions src/Dibi/Drivers/SqliteDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,9 @@
*/
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 */
Expand Down Expand Up @@ -100,19 +95,19 @@ public static function createException(string $message, $code, string $sql): Dib
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);

Expand Down
3 changes: 1 addition & 2 deletions src/Dibi/Drivers/SqliteReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
*/
class SqliteReflector implements Dibi\Reflector
{
/** @var Dibi\Driver */
private $driver;
private Dibi\Driver $driver;


public function __construct(Dibi\Driver $driver)
Expand Down
3 changes: 1 addition & 2 deletions src/Dibi/Drivers/SqliteResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
*/
class SqliteResult implements Dibi\ResultDriver
{
/** @var \SQLite3Result */
private $resultSet;
private \SQLite3Result $resultSet;


public function __construct(\SQLite3Result $resultSet)
Expand Down
Loading

0 comments on commit 7acef0c

Please sign in to comment.