diff --git a/examples/using-substitutions.php b/examples/using-substitutions.php index d10d85a1..058ed47b 100644 --- a/examples/using-substitutions.php +++ b/examples/using-substitutions.php @@ -45,7 +45,7 @@ function substFallBack($expr) // define callback -$dibi->getSubstitutes()->setCallback('substFallBack'); +$dibi->getSubstitutes()->setCallback(substFallBack(...)); // define substitutes as constants define('SUBST_ACCOUNT', 'eshop_'); diff --git a/src/Dibi/Bridges/Tracy/Panel.php b/src/Dibi/Bridges/Tracy/Panel.php index d5695e84..f53e5002 100644 --- a/src/Dibi/Bridges/Tracy/Panel.php +++ b/src/Dibi/Bridges/Tracy/Panel.php @@ -36,8 +36,8 @@ class Panel implements Tracy\IBarPanel public function register(Dibi\Connection $connection): void { Tracy\Debugger::getBar()->addPanel($this); - Tracy\Debugger::getBlueScreen()->addPanel([self::class, 'renderException']); - $connection->onEvent[] = [$this, 'logEvent']; + Tracy\Debugger::getBlueScreen()->addPanel(self::renderException(...)); + $connection->onEvent[] = $this->logEvent(...); } diff --git a/src/Dibi/Drivers/PostgreDriver.php b/src/Dibi/Drivers/PostgreDriver.php index ea5d080a..40b76b3d 100644 --- a/src/Dibi/Drivers/PostgreDriver.php +++ b/src/Dibi/Drivers/PostgreDriver.php @@ -24,13 +24,12 @@ use function in_array, is_array, is_resource, strlen; * - schema => the schema search path * - charset => character encoding to set (default is utf8) * - persistent (bool) => try to find a persistent link? - * - resource (resource) => existing connection resource + * - resource (PgSql\Connection) => existing connection resource * - connect_type (int) => see pg_connect() */ class PostgreDriver implements Dibi\Driver { - /** @var resource|PgSql\Connection */ - private $connection; + private PgSql\Connection $connection; private ?int $affectedRows; @@ -73,7 +72,7 @@ class PostgreDriver implements Dibi\Driver restore_error_handler(); } - if (!is_resource($this->connection) && !$this->connection instanceof PgSql\Connection) { + if (!$this->connection instanceof PgSql\Connection) { throw new Dibi\DriverException($error ?: 'Connecting error.'); } @@ -119,7 +118,7 @@ class PostgreDriver implements Dibi\Driver if ($res === false) { throw static::createException(pg_last_error($this->connection), null, $sql); - } elseif (is_resource($res) || $res instanceof PgSql\Result) { + } elseif ($res instanceof PgSql\Result) { $this->affectedRows = Helpers::false2Null(pg_affected_rows($res)); if (pg_num_fields($res)) { return $this->createResultDriver($res); @@ -223,13 +222,10 @@ class PostgreDriver implements Dibi\Driver /** * Returns the connection resource. - * @return resource|null */ - public function getResource(): mixed + public function getResource(): PgSql\Connection { - return is_resource($this->connection) || $this->connection instanceof PgSql\Connection - ? $this->connection - : null; + return $this->connection; } @@ -244,9 +240,8 @@ class PostgreDriver implements Dibi\Driver /** * Result set driver factory. - * @param resource $resource */ - public function createResultDriver($resource): PostgreResult + public function createResultDriver(PgSql\Result $resource): PostgreResult { return new PostgreResult($resource); } diff --git a/src/Dibi/Drivers/PostgreResult.php b/src/Dibi/Drivers/PostgreResult.php index 25f0011f..d2e9cf49 100644 --- a/src/Dibi/Drivers/PostgreResult.php +++ b/src/Dibi/Drivers/PostgreResult.php @@ -21,8 +21,7 @@ use function is_resource; class PostgreResult implements Dibi\ResultDriver { public function __construct( - /** @var resource|PgSql\Result */ - private $resultSet, + private PgSql\Result $resultSet, ) { } @@ -89,13 +88,10 @@ class PostgreResult implements Dibi\ResultDriver /** * Returns the result set resource. - * @return resource|PgSql\Result|null */ - public function getResultResource(): mixed + public function getResultResource(): PgSql\Result { - return is_resource($this->resultSet) || $this->resultSet instanceof PgSql\Result - ? $this->resultSet - : null; + return $this->resultSet; } diff --git a/src/Dibi/Fluent.php b/src/Dibi/Fluent.php index 4519bff8..0f72cbfa 100644 --- a/src/Dibi/Fluent.php +++ b/src/Dibi/Fluent.php @@ -115,7 +115,7 @@ class Fluent implements IDataSource $this->connection = $connection; if (!isset(self::$normalizer)) { - self::$normalizer = new HashMap([self::class, '_formatClause']); + self::$normalizer = new HashMap(self::_formatClause(...)); } } diff --git a/src/Dibi/Helpers.php b/src/Dibi/Helpers.php index 7224fd60..6db7b167 100644 --- a/src/Dibi/Helpers.php +++ b/src/Dibi/Helpers.php @@ -211,7 +211,7 @@ class Helpers public static function getTypeCache(): HashMap { if (!isset(self::$types)) { - self::$types = new HashMap([self::class, 'detectType']); + self::$types = new HashMap(self::detectType(...)); } return self::$types; diff --git a/src/Dibi/Translator.php b/src/Dibi/Translator.php index b8df335a..cb9a80db 100644 --- a/src/Dibi/Translator.php +++ b/src/Dibi/Translator.php @@ -36,7 +36,7 @@ final class Translator { $this->connection = $connection; $this->driver = $connection->getDriver(); - $this->identifiers = new HashMap([$this, 'delimite']); + $this->identifiers = new HashMap($this->delimite(...)); } @@ -90,7 +90,7 @@ final class Translator (\?) ## 11) placeholder )/xs XX, - [$this, 'cb'], + $this->cb(...), substr($arg, $toSkip), ); if (preg_last_error()) { @@ -436,7 +436,7 @@ final class Translator :(\S*?:)([a-zA-Z0-9._]?) )/sx XX, - [$this, 'cb'], + $this->cb(...), substr($value, $toSkip), ); if (preg_last_error()) {