1
0
mirror of https://github.com/dg/dibi.git synced 2025-07-30 19:00:13 +02:00

added typehints

This commit is contained in:
David Grudl
2018-03-21 13:48:20 +01:00
parent 837b97b582
commit 3616130959
14 changed files with 24 additions and 24 deletions

View File

@@ -23,7 +23,7 @@ class DibiExtension22 extends Nette\DI\CompilerExtension
private $debugMode;
public function __construct($debugMode = null)
public function __construct(bool $debugMode = null)
{
$this->debugMode = $debugMode;
}

View File

@@ -42,7 +42,7 @@ class Panel implements Tracy\IBarPanel
}
public function register(Dibi\Connection $connection)
public function register(Dibi\Connection $connection): void
{
Tracy\Debugger::getBar()->addPanel($this);
Tracy\Debugger::getBlueScreen()->addPanel([__CLASS__, 'renderException']);
@@ -65,7 +65,7 @@ class Panel implements Tracy\IBarPanel
/**
* Returns blue-screen custom tab.
*/
public static function renderException($e): ?array
public static function renderException(?\Throwable $e): ?array
{
if ($e instanceof Dibi\Exception && $e->getSql()) {
return [

View File

@@ -524,7 +524,7 @@ class Connection
}
public static function literal($value): Literal
public static function literal(string $value): Literal
{
return new Literal($value);
}
@@ -572,7 +572,7 @@ class Connection
}
protected function onEvent($arg)
protected function onEvent($arg): void
{
foreach ($this->onEvent ?: [] as $handler) {
$handler($arg);

View File

@@ -33,14 +33,14 @@ class DateTime extends \DateTime
}
public function modifyClone(string $modify = '')
public function modifyClone(string $modify = ''): self
{
$dolly = clone $this;
return $modify ? $dolly->modify($modify) : $dolly;
}
public function setTimestamp($timestamp)
public function setTimestamp($timestamp): self
{
$zone = $this->getTimezone();
$this->__construct('@' . $timestamp);
@@ -55,7 +55,7 @@ class DateTime extends \DateTime
}
public function __toString()
public function __toString(): string
{
return $this->format('Y-m-d H:i:s.u');
}

View File

@@ -80,7 +80,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
}
}
set_error_handler(function ($severity, $message) use (&$error) {
set_error_handler(function ($severity, string $message) use (&$error) {
$error = $message;
});
if (empty($config['persistent'])) {

View File

@@ -53,7 +53,7 @@ class Event
public $source;
public function __construct(Connection $connection, $type, $sql = null)
public function __construct(Connection $connection, int $type, string $sql = null)
{
$this->connection = $connection;
$this->type = $type;
@@ -83,7 +83,7 @@ class Event
}
public function done($result = null)
public function done($result = null): self
{
$this->result = $result;
try {

View File

@@ -286,7 +286,7 @@ class Fluent implements IDataSource
* @return Result|int result set or number of affected rows
* @throws Exception
*/
public function execute($return = null)
public function execute(string $return = null)
{
$res = $this->query($this->_export());
switch ($return) {

View File

@@ -25,13 +25,13 @@ abstract class HashMapBase
}
public function setCallback(callable $callback)
public function setCallback(callable $callback): void
{
$this->callback = $callback;
}
public function getCallback()
public function getCallback(): callable
{
return $this->callback;
}

View File

@@ -155,7 +155,7 @@ class Helpers
/** @internal */
public static function escape(Driver $driver, $value, $type)
public static function escape(Driver $driver, $value, string $type): string
{
static $types = [
Type::TEXT => 'text',
@@ -233,7 +233,7 @@ class Helpers
* Import SQL dump from file.
* @return int count of sql commands
*/
public static function loadFromFile(Connection $connection, $file, callable $onProgress = null): int
public static function loadFromFile(Connection $connection, string $file, callable $onProgress = null): int
{
@set_time_limit(0); // intentionally @

View File

@@ -33,7 +33,7 @@ class Database
private $tables;
public function __construct(Dibi\Reflector $reflector, $name)
public function __construct(Dibi\Reflector $reflector, string $name = null)
{
$this->reflector = $reflector;
$this->name = $name;

View File

@@ -29,7 +29,7 @@ class ForeignKey
private $references;
public function __construct($name, array $references)
public function __construct(string $name, array $references)
{
$this->name = $name;
$this->references = $references;

View File

@@ -303,7 +303,7 @@ class Result implements IDataSource
/**
* @deprecated
*/
private function oldFetchAssoc($assoc)
private function oldFetchAssoc(string $assoc)
{
$this->seek(0);
$row = $this->fetch();
@@ -514,7 +514,7 @@ class Result implements IDataSource
/**
* Returns column type.
*/
final public function getType($column): string
final public function getType(string $column): string
{
return $this->types[$column] ?? null;
}
@@ -533,7 +533,7 @@ class Result implements IDataSource
/**
* Returns data format.
*/
final public function getFormat($type): ?string
final public function getFormat(string $type): ?string
{
return $this->formats[$type] ?? null;
}

View File

@@ -15,7 +15,7 @@ namespace Dibi;
*/
class Row implements \ArrayAccess, \IteratorAggregate, \Countable
{
public function __construct($arr)
public function __construct(array $arr)
{
foreach ($arr as $k => $v) {
$this->$k = $v;
@@ -23,7 +23,7 @@ class Row implements \ArrayAccess, \IteratorAggregate, \Countable
}
public function toArray()
public function toArray(): array
{
return (array) $this;
}

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, $sql = null)
public function __construct(string $message = null, int $code = 0, string $severity = null, string $sql = null)
{
parent::__construct($message, $code, $sql);
$this->severity = $severity;