Skip to content

Commit

Permalink
added PHP 8 typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jun 30, 2021
1 parent 078ce09 commit a2577e3
Show file tree
Hide file tree
Showing 28 changed files with 71 additions and 104 deletions.
2 changes: 1 addition & 1 deletion src/Dibi/Bridges/Tracy/Panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Panel implements Tracy\IBarPanel
private array $events = [];


public function __construct($explain = true, int $filter = null)
public function __construct(bool $explain = true, int $filter = null)
{
$this->filter = $filter ?: Event::QUERY;
$this->explain = $explain;
Expand Down
33 changes: 10 additions & 23 deletions src/Dibi/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,8 @@ final public function isConnected(): bool
/**
* Returns configuration variable. If no $key is passed, returns the entire array.
* @see self::__construct
* @return mixed
*/
final public function getConfig(string $key = null, $default = null)
final public function getConfig(string $key = null, $default = null): mixed
{
return $key === null
? $this->config
Expand All @@ -210,21 +209,19 @@ final public function getDriver(): Driver

/**
* Generates (translates) and executes SQL query.
* @param mixed ...$args
* @throws Exception
*/
final public function query(...$args): Result
final public function query(mixed ...$args): Result
{
return $this->nativeQuery($this->translate(...$args));
}


/**
* Generates SQL query.
* @param mixed ...$args
* @throws Exception
*/
final public function translate(...$args): string
final public function translate(mixed ...$args): string
{
if (!$this->driver) {
$this->connect();
Expand All @@ -235,9 +232,8 @@ final public function translate(...$args): string

/**
* Generates and prints SQL query.
* @param mixed ...$args
*/
final public function test(...$args): bool
final public function test(mixed ...$args): bool
{
try {
Helpers::dump($this->translate(...$args));
Expand All @@ -256,10 +252,9 @@ final public function test(...$args): bool

/**
* Generates (translates) and returns SQL query as DataSource.
* @param mixed ...$args
* @throws Exception
*/
final public function dataSource(...$args): DataSource
final public function dataSource(mixed ...$args): DataSource
{
return new DataSource($this->translate(...$args), $this);
}
Expand Down Expand Up @@ -413,10 +408,7 @@ public function rollback(string $savepoint = null): void
}


/**
* @return mixed
*/
public function transaction(callable $callback)
public function transaction(callable $callback): mixed
{
if ($this->transactionDepth === 0) {
$this->begin();
Expand Down Expand Up @@ -520,45 +512,40 @@ public function substitute(string $value): string

/**
* Executes SQL query and fetch result - shortcut for query() & fetch().
* @param mixed ...$args
* @throws Exception
*/
public function fetch(...$args): ?Row
public function fetch(mixed ...$args): ?Row
{
return $this->query($args)->fetch();
}


/**
* Executes SQL query and fetch results - shortcut for query() & fetchAll().
* @param mixed ...$args
* @return Row[]|array[]
* @throws Exception
*/
public function fetchAll(...$args): array
public function fetchAll(mixed ...$args): array
{
return $this->query($args)->fetchAll();
}


/**
* Executes SQL query and fetch first column - shortcut for query() & fetchSingle().
* @param mixed ...$args
* @return mixed
* @throws Exception
*/
public function fetchSingle(...$args)
public function fetchSingle(mixed ...$args): mixed
{
return $this->query($args)->fetchSingle();
}


/**
* Executes SQL query and fetch pairs - shortcut for query() & fetchPairs().
* @param mixed ...$args
* @throws Exception
*/
public function fetchPairs(...$args): array
public function fetchPairs(mixed ...$args): array
{
return $this->query($args)->fetchPairs();
}
Expand Down
10 changes: 5 additions & 5 deletions src/Dibi/DataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct(string $sql, Connection $connection)
* @param string|array $col column name or array of column names
* @param string $as column alias
*/
public function select($col, string $as = null): self
public function select(string|array $col, string $as = null): static
{
if (is_array($col)) {
$this->cols = $col;
Expand All @@ -70,7 +70,7 @@ public function select($col, string $as = null): self
/**
* Adds conditions to query.
*/
public function where($cond): self
public function where($cond): static
{
$this->conds[] = is_array($cond)
? $cond // TODO: not consistent with select and orderBy
Expand All @@ -84,7 +84,7 @@ public function where($cond): self
* Selects columns to order by.
* @param string|array $row column name or array of column names
*/
public function orderBy($row, string $direction = 'ASC'): self
public function orderBy(string|array $row, string $direction = 'ASC'): static
{
if (is_array($row)) {
$this->sorting = $row;
Expand All @@ -99,7 +99,7 @@ public function orderBy($row, string $direction = 'ASC'): self
/**
* Limits number of rows.
*/
public function applyLimit(int $limit, int $offset = null): self
public function applyLimit(int $limit, int $offset = null): static
{
$this->limit = $limit;
$this->offset = $offset;
Expand Down Expand Up @@ -148,7 +148,7 @@ public function fetch(): ?Row
* Like fetch(), but returns only first field.
* @return mixed value on success, null if no next record
*/
public function fetchSingle()
public function fetchSingle(): mixed
{
return $this->getResult()->fetchSingle();
}
Expand Down
5 changes: 1 addition & 4 deletions src/Dibi/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ class DateTime extends \DateTimeImmutable
{
use Strict;

/**
* @param string|int $time
*/
public function __construct($time = 'now', \DateTimeZone $timezone = null)
public function __construct(string|int $time = 'now', \DateTimeZone $timezone = null)
{
$timezone = $timezone ?: new \DateTimeZone(date_default_timezone_get());
if (is_numeric($time)) {
Expand Down
5 changes: 3 additions & 2 deletions src/Dibi/Drivers/DummyDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function rollback(string $savepoint = null): void
}


public function getResource()
public function getResource(): mixed
{
return null;
}
Expand Down Expand Up @@ -171,8 +171,9 @@ public function free(): void
}


public function getResultResource()
public function getResultResource(): mixed
{
return null;
}


Expand Down
2 changes: 1 addition & 1 deletion src/Dibi/Drivers/FirebirdDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public function inTransaction(): bool
* Returns the connection resource.
* @return resource|null
*/
public function getResource()
public function getResource(): mixed
{
return is_resource($this->connection) ? $this->connection : null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Dibi/Drivers/FirebirdResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function free(): void
* Returns the result set resource.
* @return resource|null
*/
public function getResultResource()
public function getResultResource(): mixed
{
$this->autoFree = false;
return is_resource($this->resultSet) ? $this->resultSet : null;
Expand Down
5 changes: 1 addition & 4 deletions src/Dibi/Drivers/MySqliDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@ public function query(string $sql): ?Dibi\ResultDriver
}


/**
* @param int|string $code
*/
public static function createException(string $message, $code, string $sql): Dibi\DriverException
public static function createException(string $message, int|string $code, string $sql): Dibi\DriverException
{
if (in_array($code, [1216, 1217, 1451, 1452, 1701], true)) {
return new Dibi\ForeignKeyConstraintViolationException($message, $code, $sql);
Expand Down
2 changes: 1 addition & 1 deletion src/Dibi/Drivers/NoDataResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function getResultColumns(): array
}


public function getResultResource()
public function getResultResource(): mixed
{
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Dibi/Drivers/OdbcDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function inTransaction(): bool
* Returns the connection resource.
* @return resource|null
*/
public function getResource()
public function getResource(): mixed
{
return is_resource($this->connection) ? $this->connection : null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Dibi/Drivers/OdbcResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function getResultColumns(): array
* Returns the result set resource.
* @return resource|null
*/
public function getResultResource()
public function getResultResource(): mixed
{
$this->autoFree = false;
return is_resource($this->resultSet) ? $this->resultSet : null;
Expand Down
2 changes: 1 addition & 1 deletion src/Dibi/Drivers/OracleDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function rollback(string $savepoint = null): void
* Returns the connection resource.
* @return resource|null
*/
public function getResource()
public function getResource(): mixed
{
return is_resource($this->connection) ? $this->connection : null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Dibi/Drivers/OracleResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function getResultColumns(): array
* Returns the result set resource.
* @return resource|null
*/
public function getResultResource()
public function getResultResource(): mixed
{
$this->autoFree = false;
return is_resource($this->resultSet) ? $this->resultSet : null;
Expand Down
2 changes: 1 addition & 1 deletion src/Dibi/Drivers/PostgreDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public function inTransaction(): bool
* Returns the connection resource.
* @return resource|null
*/
public function getResource()
public function getResource(): mixed
{
return is_resource($this->connection) ? $this->connection : null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Dibi/Drivers/PostgreResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function getResultColumns(): array
* Returns the result set resource.
* @return resource|null
*/
public function getResultResource()
public function getResultResource(): mixed
{
$this->autoFree = false;
return is_resource($this->resultSet) ? $this->resultSet : null;
Expand Down
2 changes: 1 addition & 1 deletion src/Dibi/Drivers/SqlsrvDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function rollback(string $savepoint = null): void
* Returns the connection resource.
* @return resource|null
*/
public function getResource()
public function getResource(): mixed
{
return is_resource($this->connection) ? $this->connection : null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Dibi/Drivers/SqlsrvResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function getResultColumns(): array
* Returns the result set resource.
* @return resource|null
*/
public function getResultResource()
public function getResultResource(): mixed
{
$this->autoFree = false;
return is_resource($this->resultSet) ? $this->resultSet : null;
Expand Down
5 changes: 1 addition & 4 deletions src/Dibi/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ public function __construct(Connection $connection, int $type, string $sql = nul
}


/**
* @param Result|DriverException|null $result
*/
public function done($result = null): self
public function done(Result|DriverException $result = null): static
{
$this->result = $result;
try {
Expand Down
Loading

0 comments on commit a2577e3

Please sign in to comment.