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

type fixes

This commit is contained in:
David Grudl
2018-04-17 10:38:07 +02:00
parent ab7683a3d2
commit 5a2332899b
19 changed files with 46 additions and 54 deletions

View File

@@ -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;
}

View File

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

View File

@@ -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

View File

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

View File

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

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

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

View File

@@ -14,7 +14,7 @@ class Helpers
{
use Strict;
/** @var array */
/** @var HashMap */
private static $types;

View File

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

View File

@@ -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;
}

View File

@@ -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
{

View File

@@ -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)
{

View File

@@ -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':

View File

@@ -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

View File

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

View File

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