From 5a2332899bb8b931c94db8c262c4606959c54694 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 17 Apr 2018 10:38:07 +0200 Subject: [PATCH] type fixes --- src/Dibi/Bridges/Nette/DibiExtension22.php | 2 +- src/Dibi/Bridges/Tracy/Panel.php | 4 +-- src/Dibi/Connection.php | 33 +++++++++------------- src/Dibi/DataSource.php | 6 ++-- src/Dibi/Drivers/MsSqlReflector.php | 2 +- src/Dibi/Drivers/MySqliDriver.php | 2 +- src/Dibi/Drivers/PdoDriver.php | 4 +-- src/Dibi/Drivers/Sqlite3Driver.php | 2 +- src/Dibi/Event.php | 4 +-- src/Dibi/Fluent.php | 6 ++-- src/Dibi/Helpers.php | 2 +- src/Dibi/Loggers/FirePhpLogger.php | 2 +- src/Dibi/Reflection/Database.php | 4 +-- src/Dibi/Result.php | 8 +++--- src/Dibi/Row.php | 2 +- src/Dibi/Translator.php | 6 ++-- src/Dibi/dibi.php | 8 +++--- src/Dibi/exceptions.php | 2 +- src/Dibi/interfaces.php | 1 - 19 files changed, 46 insertions(+), 54 deletions(-) diff --git a/src/Dibi/Bridges/Nette/DibiExtension22.php b/src/Dibi/Bridges/Nette/DibiExtension22.php index b4e55417..0f155aac 100644 --- a/src/Dibi/Bridges/Nette/DibiExtension22.php +++ b/src/Dibi/Bridges/Nette/DibiExtension22.php @@ -23,7 +23,7 @@ class DibiExtension22 extends Nette\DI\CompilerExtension private $debugMode; - public function __construct(bool $debugMode = null) + public function __construct(bool $debugMode = false) { $this->debugMode = $debugMode; } diff --git a/src/Dibi/Bridges/Tracy/Panel.php b/src/Dibi/Bridges/Tracy/Panel.php index ddb5a37d..87b3363f 100644 --- a/src/Dibi/Bridges/Tracy/Panel.php +++ b/src/Dibi/Bridges/Tracy/Panel.php @@ -25,7 +25,7 @@ class Panel implements Tracy\IBarPanel /** @var int maximum SQL length */ public static $maxLength = 1000; - /** @var bool explain queries? */ + /** @var bool|string explain queries? */ public $explain; /** @var int */ @@ -35,7 +35,7 @@ class Panel implements Tracy\IBarPanel private $events = []; - public function __construct(bool $explain = true, int $filter = null) + public function __construct($explain = true, int $filter = null) { $this->filter = $filter ?: Event::QUERY; $this->explain = $explain; diff --git a/src/Dibi/Connection.php b/src/Dibi/Connection.php index 31b205e8..44e7ed9f 100644 --- a/src/Dibi/Connection.php +++ b/src/Dibi/Connection.php @@ -31,7 +31,7 @@ class Connection implements IConnection /** @var Driver */ private $driver; - /** @var Translator */ + /** @var Translator|null */ private $translator; /** @var bool Is connected? */ @@ -50,7 +50,7 @@ class Connection implements IConnection * - run (bool) => enable profiler? * - file => file to log * - substitutes (array) => map of driver specific substitutes (under development) - * @param mixed $config connection parameters + * @param array $config connection parameters * @throws Exception */ public function __construct($config, string $name = null) @@ -198,7 +198,7 @@ class Connection implements IConnection /** * Generates (translates) and executes SQL query. - * @param mixed $args + * @param mixed ...$args * @return Result|int result set or number of affected rows * @throws Exception */ @@ -210,7 +210,7 @@ class Connection implements IConnection /** * Generates SQL query. - * @param mixed $args + * @param mixed ...$args * @throws Exception */ final public function translate(...$args): string @@ -221,7 +221,7 @@ class Connection implements IConnection /** * Generates and prints SQL query. - * @param mixed $args + * @param mixed ...$args */ final public function test(...$args): bool { @@ -242,7 +242,7 @@ class Connection implements IConnection /** * Generates (translates) and returns SQL query as DataSource. - * @param mixed $args + * @param mixed ...$args * @throws Exception */ final public function dataSource(...$args): DataSource @@ -267,7 +267,7 @@ class Connection implements IConnection /** * Executes the SQL query. - * @return Result|int result set or number of affected rows + * @return Result|int|null result set or number of affected rows * @throws Exception */ final public function nativeQuery(string $sql) @@ -425,21 +425,16 @@ class Connection implements IConnection } - public function update(string $table, array $args): Fluent + public function update(string $table, iterable $args): Fluent { - if (!(is_array($args) || $args instanceof Traversable)) { - throw new \InvalidArgumentException('Arguments must be array or Traversable.'); - } return $this->command()->update('%n', $table)->set($args); } - public function insert(string $table, array $args): Fluent + public function insert(string $table, iterable $args): Fluent { if ($args instanceof Traversable) { $args = iterator_to_array($args); - } elseif (!is_array($args)) { - throw new \InvalidArgumentException('Arguments must be array or Traversable.'); } return $this->command()->insert() ->into('%n', $table, '(%n)', array_keys($args))->values('%l', $args); @@ -480,7 +475,7 @@ class Connection implements IConnection /** * Executes SQL query and fetch result - shortcut for query() & fetch(). - * @param mixed $args + * @param mixed ...$args * @throws Exception */ public function fetch(...$args): ?Row @@ -491,8 +486,8 @@ class Connection implements IConnection /** * Executes SQL query and fetch results - shortcut for query() & fetchAll(). - * @param mixed $args - * @return Row[] + * @param mixed ...$args + * @return Row[]|array[] * @throws Exception */ public function fetchAll(...$args): array @@ -503,7 +498,7 @@ class Connection implements IConnection /** * Executes SQL query and fetch first column - shortcut for query() & fetchSingle(). - * @param mixed $args + * @param mixed ...$args * @return mixed * @throws Exception */ @@ -515,7 +510,7 @@ class Connection implements IConnection /** * Executes SQL query and fetch pairs - shortcut for query() & fetchPairs(). - * @param mixed $args + * @param mixed ...$args * @throws Exception */ public function fetchPairs(...$args): array diff --git a/src/Dibi/DataSource.php b/src/Dibi/DataSource.php index 1efdd48e..7967f2d1 100644 --- a/src/Dibi/DataSource.php +++ b/src/Dibi/DataSource.php @@ -23,13 +23,13 @@ class DataSource implements IDataSource /** @var string */ private $sql; - /** @var Result */ + /** @var Result|null */ private $result; - /** @var int */ + /** @var int|null */ private $count; - /** @var int */ + /** @var int|null */ private $totalCount; /** @var array */ diff --git a/src/Dibi/Drivers/MsSqlReflector.php b/src/Dibi/Drivers/MsSqlReflector.php index e0aa1394..96a12c0d 100644 --- a/src/Dibi/Drivers/MsSqlReflector.php +++ b/src/Dibi/Drivers/MsSqlReflector.php @@ -53,7 +53,7 @@ class MsSqlReflector implements Dibi\Reflector /** * Returns count of rows in a table */ - public function getTableCount(string $table, bool $fallback = true): int + public function getTableCount(string $table, bool $fallback = true): ?int { if (empty($table)) { return null; diff --git a/src/Dibi/Drivers/MySqliDriver.php b/src/Dibi/Drivers/MySqliDriver.php index caea7a53..c6176c73 100644 --- a/src/Dibi/Drivers/MySqliDriver.php +++ b/src/Dibi/Drivers/MySqliDriver.php @@ -243,7 +243,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver /** * Returns the connection resource. */ - public function getResource(): \mysqli + public function getResource(): ?\mysqli { return @$this->connection->thread_id ? $this->connection : null; } diff --git a/src/Dibi/Drivers/PdoDriver.php b/src/Dibi/Drivers/PdoDriver.php index f11c8eb6..8326c795 100644 --- a/src/Dibi/Drivers/PdoDriver.php +++ b/src/Dibi/Drivers/PdoDriver.php @@ -30,7 +30,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver { use Dibi\Strict; - /** @var PDO Connection resource */ + /** @var PDO|null Connection resource */ private $connection; /** @var \PDOStatement|null Resultset resource */ @@ -190,7 +190,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver /** * Returns the connection resource. */ - public function getResource(): PDO + public function getResource(): ?PDO { return $this->connection; } diff --git a/src/Dibi/Drivers/Sqlite3Driver.php b/src/Dibi/Drivers/Sqlite3Driver.php index b2992ca8..02b8150c 100644 --- a/src/Dibi/Drivers/Sqlite3Driver.php +++ b/src/Dibi/Drivers/Sqlite3Driver.php @@ -202,7 +202,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver /** * Returns the connection resource. */ - public function getResource(): SQLite3 + public function getResource(): ?SQLite3 { return $this->connection; } diff --git a/src/Dibi/Event.php b/src/Dibi/Event.php index e40f1dcc..dcbfc4bf 100644 --- a/src/Dibi/Event.php +++ b/src/Dibi/Event.php @@ -46,7 +46,7 @@ class Event /** @var float */ public $time; - /** @var int */ + /** @var int|null */ public $count; /** @var array */ @@ -77,7 +77,7 @@ class Event } } - \dibi::$elapsedTime = false; + \dibi::$elapsedTime = null; \dibi::$numOfQueries++; \dibi::$sql = $sql; } diff --git a/src/Dibi/Fluent.php b/src/Dibi/Fluent.php index e6ac84f2..c9b3025a 100644 --- a/src/Dibi/Fluent.php +++ b/src/Dibi/Fluent.php @@ -15,7 +15,7 @@ namespace Dibi; * * @method Fluent select(...$field) * @method Fluent distinct() - * @method Fluent from($table) + * @method Fluent from($table, ...$args) * @method Fluent where(...$cond) * @method Fluent groupBy(...$field) * @method Fluent having(...$cond) @@ -97,7 +97,7 @@ class Fluent implements IDataSource /** @var array */ private $flags = []; - /** @var array */ + /** @var array|null */ private $cursor; /** @var HashMap normalized clauses */ @@ -268,7 +268,6 @@ class Fluent implements IDataSource /** * Adds Result setup. - * @param mixed $method */ public function setupResult(string $method): self { @@ -282,7 +281,6 @@ class Fluent implements IDataSource /** * Generates and executes SQL query. - * @param mixed $return what to return? * @return Result|int result set or number of affected rows * @throws Exception */ diff --git a/src/Dibi/Helpers.php b/src/Dibi/Helpers.php index 0918b974..74f8d58d 100644 --- a/src/Dibi/Helpers.php +++ b/src/Dibi/Helpers.php @@ -14,7 +14,7 @@ class Helpers { use Strict; - /** @var array */ + /** @var HashMap */ private static $types; diff --git a/src/Dibi/Loggers/FirePhpLogger.php b/src/Dibi/Loggers/FirePhpLogger.php index 00732756..ef5ad7f3 100644 --- a/src/Dibi/Loggers/FirePhpLogger.php +++ b/src/Dibi/Loggers/FirePhpLogger.php @@ -31,7 +31,7 @@ class FirePhpLogger /** @var int */ public $filter; - /** @var int Elapsed time for all queries */ + /** @var float Elapsed time for all queries */ public $totalTime = 0; /** @var int Number of all queries */ diff --git a/src/Dibi/Reflection/Database.php b/src/Dibi/Reflection/Database.php index 028b75be..7246edc9 100644 --- a/src/Dibi/Reflection/Database.php +++ b/src/Dibi/Reflection/Database.php @@ -26,7 +26,7 @@ class Database /** @var Dibi\Reflector */ private $reflector; - /** @var string */ + /** @var string|null */ private $name; /** @var array */ @@ -40,7 +40,7 @@ class Database } - public function getName(): string + public function getName(): ?string { return $this->name; } diff --git a/src/Dibi/Result.php b/src/Dibi/Result.php index c6927259..bb0bf188 100644 --- a/src/Dibi/Result.php +++ b/src/Dibi/Result.php @@ -44,10 +44,10 @@ class Result implements IDataSource /** @var bool Already fetched? Used for allowance for first seek(0) */ private $fetched = false; - /** @var ?string returned object class */ + /** @var string|null returned object class */ private $rowClass = Row::class; - /** @var callable returned object factory*/ + /** @var callable|null returned object factory */ private $rowFactory; /** @var array format */ @@ -96,7 +96,7 @@ class Result implements IDataSource */ final public function seek(int $row): bool { - return ($row !== 0 || $this->fetched) ? (bool) $this->getResultDriver()->seek($row) : true; + return ($row !== 0 || $this->fetched) ? $this->getResultDriver()->seek($row) : true; } @@ -204,7 +204,7 @@ class Result implements IDataSource /** * Fetches all records from table. - * @return Row[] + * @return Row[]|array[] */ final public function fetchAll(int $offset = null, int $limit = null): array { diff --git a/src/Dibi/Row.php b/src/Dibi/Row.php index 59d83a4f..2e53269e 100644 --- a/src/Dibi/Row.php +++ b/src/Dibi/Row.php @@ -31,7 +31,7 @@ class Row implements \ArrayAccess, \IteratorAggregate, \Countable /** * Converts value to DateTime object. - * @return \DateTime|string|null + * @return DateTime|string|null */ public function asDateTime(string $key, string $format = null) { diff --git a/src/Dibi/Translator.php b/src/Dibi/Translator.php index e3eea42b..82008097 100644 --- a/src/Dibi/Translator.php +++ b/src/Dibi/Translator.php @@ -41,10 +41,10 @@ final class Translator /** @var int */ private $ifLevelStart = 0; - /** @var int */ + /** @var int|null */ private $limit; - /** @var int */ + /** @var int|null */ private $offset; /** @var HashMap */ @@ -337,7 +337,7 @@ final class Translator return $value === null ? 'NULL' : $this->driver->escapeBinary($value); case 'b': // boolean - return $value === null ? 'NULL' : $this->driver->escapeBool($value); + return $value === null ? 'NULL' : $this->driver->escapeBool((bool) $value); case 'sN': // string or null case 'sn': diff --git a/src/Dibi/dibi.php b/src/Dibi/dibi.php index d7070c87..319be3c8 100644 --- a/src/Dibi/dibi.php +++ b/src/Dibi/dibi.php @@ -52,13 +52,13 @@ class dibi ASC = 'ASC', DESC = 'DESC'; - /** @var string Last SQL command @see dibi::query() */ + /** @var string|null Last SQL command @see dibi::query() */ public static $sql; - /** @var int Elapsed time for last query */ + /** @var float|null Elapsed time for last query */ public static $elapsedTime; - /** @var int Elapsed time for all queries */ + /** @var float Elapsed time for all queries */ public static $totalTime; /** @var int Number or queries */ @@ -170,7 +170,7 @@ class dibi /** * Prints out a syntax highlighted version of the SQL command or Result. - * @param string|Result $sql + * @param string|Dibi\Result $sql * @param bool $return return output instead of printing it? */ public static function dump($sql = null, bool $return = false): ?string diff --git a/src/Dibi/exceptions.php b/src/Dibi/exceptions.php index 3214fe4d..4bdbf69a 100644 --- a/src/Dibi/exceptions.php +++ b/src/Dibi/exceptions.php @@ -93,7 +93,7 @@ class ProcedureException extends Exception /** * Construct the exception. */ - public function __construct(string $message = null, int $code = 0, string $severity = null, string $sql = null) + public function __construct(string $message = '', int $code = 0, string $severity = '', string $sql = null) { parent::__construct($message, $code, $sql); $this->severity = $severity; diff --git a/src/Dibi/interfaces.php b/src/Dibi/interfaces.php index 21e509c9..37e7ff16 100644 --- a/src/Dibi/interfaces.php +++ b/src/Dibi/interfaces.php @@ -223,7 +223,6 @@ interface IConnection /** * Generates (translates) and executes SQL query. - * @param mixed $args * @return Result|int result set or number of affected rows * @throws Exception */