diff --git a/src/PDO.php b/src/PDO.php index 17d7124..fc13a51 100755 --- a/src/PDO.php +++ b/src/PDO.php @@ -12,12 +12,12 @@ class PDO extends NativePdo * Logged queries. * @var array */ - protected $log = []; + protected array $log = []; /** * @inheritDoc */ - public function __construct($dsn, $username = null, $passwd = null, $options = null) + public function __construct(string $dsn, ?string $username = null, ?string $passwd = null, ?array $options = null) { parent::__construct($dsn, $username, $passwd, $options); $this->setAttribute(self::ATTR_STATEMENT_CLASS, [PDOStatement::class, [$this]]); @@ -26,7 +26,7 @@ public function __construct($dsn, $username = null, $passwd = null, $options = n /** * @inheritDoc */ - public function exec($statement) + public function exec(string $statement): int|false { $start = microtime(true); $result = parent::exec($statement); @@ -38,7 +38,7 @@ public function exec($statement) /** * @inheritDoc */ - public function query($statement, $mode = PDO::FETCH_ASSOC, ...$ctorargs) + public function query(string $statement, ?int $mode = PDO::FETCH_ASSOC, ...$ctorargs): PDOStatement|false { $start = microtime(true); $result = parent::query($statement, $mode, ...$ctorargs); diff --git a/src/PDOStatement.php b/src/PDOStatement.php index cf6e994..98ae8bd 100755 --- a/src/PDOStatement.php +++ b/src/PDOStatement.php @@ -27,12 +27,12 @@ protected function __construct(PDO $pdo) * @inheritDoc */ public function bindParam( - $param, - &$var, - $type = PDO::PARAM_STR, - $maxLength = null, - $driverOptions = null - ) { + int|string $param, + mixed &$var, + int $type = PDO::PARAM_STR, + int $maxLength = 0, + mixed $driverOptions = null + ): bool { $this->bindings[$param] = $var; return parent::bindParam($param, $var, $type, $maxLength, $driverOptions); } @@ -40,7 +40,7 @@ public function bindParam( /** * @inheritDoc */ - public function bindValue($param, $value, $type = PDO::PARAM_STR) + public function bindValue(string|int $param, mixed $value, int $type = PDO::PARAM_STR): bool { $this->bindings[$param] = $value; return parent::bindValue($param, $value, $type); @@ -49,7 +49,7 @@ public function bindValue($param, $value, $type = PDO::PARAM_STR) /** * @inheritDoc */ - public function execute($params = null) + public function execute(?array $params = null): bool { if (is_array($params)) { $this->bindings = $params; diff --git a/src/Tracy/BarPanel.php b/src/Tracy/BarPanel.php index 1d23f1e..c2969ba 100755 --- a/src/Tracy/BarPanel.php +++ b/src/Tracy/BarPanel.php @@ -21,32 +21,25 @@ class BarPanel implements IBarPanel /** * Title - * @var string */ - public $title = 'PDO logger'; + public string $title = 'PDO logger'; /** * Title HTML attributes - * @var string */ - public $title_attributes = 'style="font-size:1.6em"'; + public string $title_attributes = 'style="font-size:1.6em"'; /** * Time table cell HTML attributes - * @var string */ - public $time_attributes = 'style="font-weight:bold;color:#333;font-family:Courier New;font-size:1.1em"'; + public string $time_attributes = 'style="font-weight:bold;color:#333;font-family:Courier New;font-size:1.1em"'; /** * Query table cell HTML attributes - * @var string */ - public $query_attributes = ''; + public string $query_attributes = ''; - /** - * @var PDO - */ - private $pdo; + private PDO $pdo; public function __construct(PDO $pdo) { @@ -55,18 +48,16 @@ public function __construct(PDO $pdo) /** * Get total queries execution time - * @return string */ - protected function getTotalTime() + protected function getTotalTime(): string { return (string) round(array_sum(array_column($this->pdo->getLog(), 'time')), 4); } /** * Renders HTML code for custom tab. - * @return string */ - public function getTab() + public function getTab(): string { $html = 'PDO queries logger '; $queries = count($this->pdo->getLog()); @@ -86,7 +77,7 @@ public function getTab() * Renders HTML code for custom panel. * @return string */ - public function getPanel() + public function getPanel(): string { if (class_exists('\SqlFormatter')) { \SqlFormatter::$pre_attributes = 'style="color: black;"';