diff --git a/.gitignore b/.gitignore index 2cac7943..8b7317af 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ /composer.lock /vendor -/.idea + +!/.idea +/.idea/* +!/.idea/codeStyles +!/.idea/codeStyles/codeStyleConfig.xml +!/.idea/codeStyles/Project.xml +!/.idea/sqldialects.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..577881fc --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,60 @@ + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 00000000..79ee123c --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/src/Bridges/NetteCaching/CachedPlatform.php b/src/Bridges/NetteCaching/CachedPlatform.php index e1ecbcbb..485a4cff 100644 --- a/src/Bridges/NetteCaching/CachedPlatform.php +++ b/src/Bridges/NetteCaching/CachedPlatform.php @@ -1,13 +1,8 @@ cache->load(self::CACHE_VERSION . '.tables.' . $schema , function () use ($schema) { + return $this->cache->load(self::CACHE_VERSION . '.tables.' . $schema, function () use ($schema) { return $this->platform->getTables($schema); }); } diff --git a/src/Bridges/NetteDI/DbalExtension.php b/src/Bridges/NetteDI/DbalExtension.php index c0d42b6a..34f60b6a 100644 --- a/src/Bridges/NetteDI/DbalExtension.php +++ b/src/Bridges/NetteDI/DbalExtension.php @@ -1,13 +1,8 @@ addSetup('@Tracy\BlueScreen::addPanel', [BluescreenQueryPanel::class . '::renderBluescreenPanel']); - $definition->addSetup(ConnectionPanel::class . '::install', ['@self', $config['panelQueryExplain'] ?? true]); + $definition->addSetup( + ConnectionPanel::class . '::install', + ['@self', $config['panelQueryExplain'] ?? true] + ); } } } diff --git a/src/Bridges/NetteTracy/BluescreenQueryPanel.php b/src/Bridges/NetteTracy/BluescreenQueryPanel.php index 669283c0..f1bc284a 100644 --- a/src/Bridges/NetteTracy/BluescreenQueryPanel.php +++ b/src/Bridges/NetteTracy/BluescreenQueryPanel.php @@ -1,13 +1,8 @@

Queries:

@@ -46,36 +65,38 @@ namespace Nextras\Dbal\Bridges\NetteTracy; - - - -
- - - - copy - - explain - - - $foo): ?> - - - - - - - - - - -
- - - + ?> + + + +
+ + + + copy + + explain + + + $foo): ?> + + + + + + + + + + +
+ + +

...and more

diff --git a/src/Bridges/NetteTracy/ConnectionPanel.php b/src/Bridges/NetteTracy/ConnectionPanel.php index 6bf06d31..79b3594d 100644 --- a/src/Bridges/NetteTracy/ConnectionPanel.php +++ b/src/Bridges/NetteTracy/ConnectionPanel.php @@ -1,13 +1,8 @@ - + diff --git a/src/Bridges/SymfonyBundle/DataCollector/QueryDataCollector.php b/src/Bridges/SymfonyBundle/DataCollector/QueryDataCollector.php index faef2963..c2c5a15d 100644 --- a/src/Bridges/SymfonyBundle/DataCollector/QueryDataCollector.php +++ b/src/Bridges/SymfonyBundle/DataCollector/QueryDataCollector.php @@ -1,13 +1,8 @@ {{ query.rowsCount }} {% if query.rowsCount == 1 %}row{% else %}rows{% endif %} {% endif %} - copy + copy {% if query.explain != null %} - show explain + show explain
diff --git a/src/Connection.php b/src/Connection.php index a763ad14..17a206bc 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -1,13 +1,8 @@ config['driver']); $class = "Nextras\\Dbal\\Drivers\\{$name}\\{$name}Driver"; - return new $class; + return new $class(); } } diff --git a/src/Drivers/Exception/DriverException.php b/src/Drivers/Exception/DriverException.php index bba899d0..6ba6cf3a 100644 --- a/src/Drivers/Exception/DriverException.php +++ b/src/Drivers/Exception/DriverException.php @@ -2,6 +2,7 @@ namespace Nextras\Dbal\Drivers\Exception; + use Exception; diff --git a/src/Drivers/Exception/QueryException.php b/src/Drivers/Exception/QueryException.php index 4dfc9595..38b85886 100644 --- a/src/Drivers/Exception/QueryException.php +++ b/src/Drivers/Exception/QueryException.php @@ -2,6 +2,7 @@ namespace Nextras\Dbal\Drivers\Exception; + use Exception; diff --git a/src/Drivers/IDriver.php b/src/Drivers/IDriver.php index 7a594a9a..47aed03a 100644 --- a/src/Drivers/IDriver.php +++ b/src/Drivers/IDriver.php @@ -1,13 +1,8 @@ connection !== null); if ( - !isset($params['sslKey']) && - !isset($params['sslCert']) && - !isset($params['sslCa']) && - !isset($params['sslCapath']) && - !isset($params['sslCipher']) + !isset($params['sslKey']) + && !isset($params['sslCert']) + && !isset($params['sslCa']) + && !isset($params['sslCapath']) + && !isset($params['sslCipher']) ) { return; } diff --git a/src/Drivers/Mysqli/MysqliEmptyResultAdapter.php b/src/Drivers/Mysqli/MysqliEmptyResultAdapter.php index 41323211..e4a38f90 100644 --- a/src/Drivers/Mysqli/MysqliEmptyResultAdapter.php +++ b/src/Drivers/Mysqli/MysqliEmptyResultAdapter.php @@ -1,13 +1,8 @@ */ protected static $types = [ - MYSQLI_TYPE_TIME => self::TYPE_DRIVER_SPECIFIC, - MYSQLI_TYPE_DATE => self::TYPE_DATETIME, - MYSQLI_TYPE_DATETIME => self::TYPE_DATETIME, - MYSQLI_TYPE_TIMESTAMP => self::TYPE_DRIVER_SPECIFIC | self::TYPE_DATETIME, - - MYSQLI_TYPE_BIT => self::TYPE_INT, // returned as int - MYSQLI_TYPE_INT24 => self::TYPE_INT, - MYSQLI_TYPE_INTERVAL => self::TYPE_INT, - MYSQLI_TYPE_TINY => self::TYPE_INT, - MYSQLI_TYPE_SHORT => self::TYPE_INT, - MYSQLI_TYPE_LONG => self::TYPE_INT, - MYSQLI_TYPE_LONGLONG => self::TYPE_INT, - MYSQLI_TYPE_YEAR => self::TYPE_INT, - - MYSQLI_TYPE_DECIMAL => self::TYPE_FLOAT, - MYSQLI_TYPE_NEWDECIMAL => self::TYPE_FLOAT, - MYSQLI_TYPE_DOUBLE => self::TYPE_FLOAT, - MYSQLI_TYPE_FLOAT => self::TYPE_FLOAT, - - MYSQLI_TYPE_STRING => self::TYPE_AS_IS, + MYSQLI_TYPE_TIME => self::TYPE_DRIVER_SPECIFIC, + MYSQLI_TYPE_DATE => self::TYPE_DATETIME, + MYSQLI_TYPE_DATETIME => self::TYPE_DATETIME, + MYSQLI_TYPE_TIMESTAMP => self::TYPE_DRIVER_SPECIFIC | self::TYPE_DATETIME, + + MYSQLI_TYPE_BIT => self::TYPE_INT, // returned as int + MYSQLI_TYPE_INT24 => self::TYPE_INT, + MYSQLI_TYPE_INTERVAL => self::TYPE_INT, + MYSQLI_TYPE_TINY => self::TYPE_INT, + MYSQLI_TYPE_SHORT => self::TYPE_INT, + MYSQLI_TYPE_LONG => self::TYPE_INT, + MYSQLI_TYPE_LONGLONG => self::TYPE_INT, + MYSQLI_TYPE_YEAR => self::TYPE_INT, + + MYSQLI_TYPE_DECIMAL => self::TYPE_FLOAT, + MYSQLI_TYPE_NEWDECIMAL => self::TYPE_FLOAT, + MYSQLI_TYPE_DOUBLE => self::TYPE_FLOAT, + MYSQLI_TYPE_FLOAT => self::TYPE_FLOAT, + + MYSQLI_TYPE_STRING => self::TYPE_AS_IS, ]; /** diff --git a/src/Drivers/Pgsql/PgsqlDriver.php b/src/Drivers/Pgsql/PgsqlDriver.php index 8eda19e8..81df3180 100644 --- a/src/Drivers/Pgsql/PgsqlDriver.php +++ b/src/Drivers/Pgsql/PgsqlDriver.php @@ -1,13 +1,8 @@ logger = $logger; @@ -77,7 +80,7 @@ public function connect(array $params, ILogger $logger): void } } - set_error_handler(function($code, $message) { + set_error_handler(function ($code, $message) { restore_error_handler(); throw $this->createException($message, $code, null); }, E_ALL); @@ -96,7 +99,8 @@ public function connect(array $params, ILogger $logger): void } if (isset($params['searchPath'])) { - $this->loggedQuery('SET search_path TO ' . implode(', ', array_map([$this, 'convertIdentifierToSql'], (array) $params['searchPath']))); + $schemas = array_map([$this, 'convertIdentifierToSql',], (array) $params['searchPath']); + $this->loggedQuery('SET search_path TO ' . implode(', ', $schemas)); } } diff --git a/src/Drivers/Pgsql/PgsqlResultAdapter.php b/src/Drivers/Pgsql/PgsqlResultAdapter.php index 8d001dca..edcacca2 100644 --- a/src/Drivers/Pgsql/PgsqlResultAdapter.php +++ b/src/Drivers/Pgsql/PgsqlResultAdapter.php @@ -1,13 +1,8 @@ self::TYPE_DRIVER_SPECIFIC, - 'bit' => self::TYPE_DRIVER_SPECIFIC, - 'varbit' => self::TYPE_DRIVER_SPECIFIC, - 'bytea' => self::TYPE_DRIVER_SPECIFIC, - 'interval' => self::TYPE_DRIVER_SPECIFIC, - - 'int8' => self::TYPE_INT, - 'int4' => self::TYPE_INT, - 'int2' => self::TYPE_INT, - - 'numeric' => self::TYPE_FLOAT, - 'float4' => self::TYPE_FLOAT, - 'float8' => self::TYPE_FLOAT, - - 'time' => self::TYPE_DATETIME, - 'date' => self::TYPE_DATETIME, - 'timestamp' => self::TYPE_DATETIME, - 'timetz' => self::TYPE_DATETIME, + 'bool' => self::TYPE_DRIVER_SPECIFIC, + 'bit' => self::TYPE_DRIVER_SPECIFIC, + 'varbit' => self::TYPE_DRIVER_SPECIFIC, + 'bytea' => self::TYPE_DRIVER_SPECIFIC, + 'interval' => self::TYPE_DRIVER_SPECIFIC, + + 'int8' => self::TYPE_INT, + 'int4' => self::TYPE_INT, + 'int2' => self::TYPE_INT, + + 'numeric' => self::TYPE_FLOAT, + 'float4' => self::TYPE_FLOAT, + 'float8' => self::TYPE_FLOAT, + + 'time' => self::TYPE_DATETIME, + 'date' => self::TYPE_DATETIME, + 'timestamp' => self::TYPE_DATETIME, + 'timetz' => self::TYPE_DATETIME, 'timestamptz' => self::TYPE_DATETIME, ]; diff --git a/src/Drivers/Sqlsrv/SqlsrvDriver.php b/src/Drivers/Sqlsrv/SqlsrvDriver.php index 15908a96..10463770 100644 --- a/src/Drivers/Sqlsrv/SqlsrvDriver.php +++ b/src/Drivers/Sqlsrv/SqlsrvDriver.php @@ -1,13 +1,8 @@ logger = $logger; @@ -258,11 +267,12 @@ public function rollbackSavepoint(string $name): void $this->loggedQuery('ROLLBACK TRANSACTION ' . $this->convertIdentifierToSql($name)); } + public function convertToPhp(string $value, $nativeType) { if ( - $nativeType === SqlsrvResultTypes::TYPE_DECIMAL_MONEY_SMALLMONEY || - $nativeType === SqlsrvResultTypes::TYPE_NUMERIC + $nativeType === SqlsrvResultTypes::TYPE_DECIMAL_MONEY_SMALLMONEY + || $nativeType === SqlsrvResultTypes::TYPE_NUMERIC ) { return strpos($value, '.') === false ? (int) $value : (float) $value; diff --git a/src/Drivers/Sqlsrv/SqlsrvResultAdapter.php b/src/Drivers/Sqlsrv/SqlsrvResultAdapter.php index 58403898..b92396c4 100644 --- a/src/Drivers/Sqlsrv/SqlsrvResultAdapter.php +++ b/src/Drivers/Sqlsrv/SqlsrvResultAdapter.php @@ -1,13 +1,8 @@ */ protected static $types = [ - SqlsrvResultTypes::TYPE_INT => self::TYPE_INT, - SqlsrvResultTypes::TYPE_BIT => self::TYPE_BOOL, - SqlsrvResultTypes::TYPE_NUMERIC => self::TYPE_DRIVER_SPECIFIC, - SqlsrvResultTypes::TYPE_DECIMAL_MONEY_SMALLMONEY => self::TYPE_DRIVER_SPECIFIC, - SqlsrvResultTypes::TYPE_TIME => self::TYPE_DATETIME, - SqlsrvResultTypes::TYPE_DATE => self::TYPE_DATETIME, - SqlsrvResultTypes::TYPE_DATETIME_DATETIME2_SMALLDATETIME => self::TYPE_DATETIME, - SqlsrvResultTypes::TYPE_DATETIMEOFFSET => self::TYPE_DRIVER_SPECIFIC, + SqlsrvResultTypes::TYPE_INT => self::TYPE_INT, + SqlsrvResultTypes::TYPE_BIT => self::TYPE_BOOL, + SqlsrvResultTypes::TYPE_NUMERIC => self::TYPE_DRIVER_SPECIFIC, + SqlsrvResultTypes::TYPE_DECIMAL_MONEY_SMALLMONEY => self::TYPE_DRIVER_SPECIFIC, + SqlsrvResultTypes::TYPE_TIME => self::TYPE_DATETIME, + SqlsrvResultTypes::TYPE_DATE => self::TYPE_DATETIME, + SqlsrvResultTypes::TYPE_DATETIME_DATETIME2_SMALLDATETIME => self::TYPE_DATETIME, + SqlsrvResultTypes::TYPE_DATETIMEOFFSET => self::TYPE_DRIVER_SPECIFIC, ]; /** @var int|null */ diff --git a/src/Drivers/Sqlsrv/SqlsrvResultTypes.php b/src/Drivers/Sqlsrv/SqlsrvResultTypes.php index 2ffcea52..94759380 100644 --- a/src/Drivers/Sqlsrv/SqlsrvResultTypes.php +++ b/src/Drivers/Sqlsrv/SqlsrvResultTypes.php @@ -1,11 +1,5 @@ $query * @phpstan-param array $args * @throws QueryException diff --git a/src/ILogger.php b/src/ILogger.php index 740e77f1..789c8158 100644 --- a/src/ILogger.php +++ b/src/ILogger.php @@ -1,13 +1,8 @@ select !== null ? implode(', ', $this->select) : '*') . ' FROM ' . $this->getFromClauses() - . ($this->where !== null ? ' WHERE ' . ($this->where) : '') - . ($this->group ? ' GROUP BY ' . implode(', ', $this->group) : '') + . ($this->where !== null ? ' WHERE ' . ($this->where) : '') + . ($this->group ? ' GROUP BY ' . implode(', ', $this->group) : '') . ($this->having !== null ? ' HAVING ' . ($this->having) : '') - . ($this->order ? ' ORDER BY ' . implode(', ', $this->order) : ''); + . ($this->order ? ' ORDER BY ' . implode(', ', $this->order) : ''); if ($this->limit) { $query = $this->driver->modifyLimitQuery($query, $this->limit[0], $this->limit[1]); @@ -218,7 +213,13 @@ public function getFromAlias(): ?string * @deprecated QueryBuilder::innerJoin() is deprecated. Use QueryBuilder::joinInner() without $fromAlias and with $toAlias included in $toExpression. * @noinspection PhpUnusedParameterInspection */ - public function innerJoin(string $fromAlias, string $toExpression, string $toAlias, string $onExpression, ...$args): self + public function innerJoin( + string $fromAlias, + string $toExpression, + string $toAlias, + string $onExpression, + ...$args + ): self { trigger_error( 'QueryBuilder::innerJoin() is deprecated. Use QueryBuilder::joinInner() without $fromAlias and with $toAlias included in $toExpression.', @@ -233,7 +234,13 @@ public function innerJoin(string $fromAlias, string $toExpression, string $toAli * @deprecated QueryBuilder::leftJoin() is deprecated. Use QueryBuilder::joinLeft() without $fromAlias and with $toAlias included in $toExpression. * @noinspection PhpUnusedParameterInspection */ - public function leftJoin(string $fromAlias, string $toExpression, string $toAlias, string $onExpression, ...$args): self + public function leftJoin( + string $fromAlias, + string $toExpression, + string $toAlias, + string $onExpression, + ...$args + ): self { trigger_error( 'QueryBuilder::leftJoin() is deprecated. Use QueryBuilder::joinLeft() without $fromAlias and with $toAlias included in $toExpression.', @@ -248,7 +255,13 @@ public function leftJoin(string $fromAlias, string $toExpression, string $toAlia * @deprecated QueryBuilder::rightJoin() is deprecated. Use QueryBuilder::joinRight() without $fromAlias and with $toAlias included in $toExpression. * @noinspection PhpUnusedParameterInspection */ - public function rightJoin(string $fromAlias, string $toExpression, string $toAlias, string $onExpression, ...$args): self + public function rightJoin( + string $fromAlias, + string $toExpression, + string $toAlias, + string $onExpression, + ...$args + ): self { trigger_error( 'QueryBuilder::rightJoin() is deprecated. Use QueryBuilder::joinRight() without $fromAlias and with $toAlias included in $toExpression.', diff --git a/src/Result/Result.php b/src/Result/Result.php index aee98084..83fb3b7c 100644 --- a/src/Result/Result.php +++ b/src/Result/Result.php @@ -1,13 +1,8 @@ iteratorIndex; @@ -290,7 +284,6 @@ public function seek($index): void // === Countable =================================================================================================== - public function count(): int { return $this->adapter->getRowsCount(); diff --git a/src/Result/Row.php b/src/Result/Row.php index fe7bc5de..f7c96445 100644 --- a/src/Result/Row.php +++ b/src/Result/Row.php @@ -1,13 +1,8 @@ toArray())); - throw new InvalidArgumentException("Column '$name' does not exist" . ($closest ? ", did you mean '$closest'?" : ".")); + throw new InvalidArgumentException("Column '$name' does not exist" . ($closest ? ", did you mean '$closest'?" : ".")); } diff --git a/src/SqlProcessor.php b/src/SqlProcessor.php index e198cea0..d0f899b1 100644 --- a/src/SqlProcessor.php +++ b/src/SqlProcessor.php @@ -1,12 +1,7 @@ identifierToSql($value); @@ -195,7 +190,7 @@ public function processModifier(string $type, $value): string return $value; } - break; + break; case 'integer': switch ($type) { case 'any': @@ -208,7 +203,7 @@ public function processModifier(string $type, $value): string return $this->driver->convertJsonToSql($value); } - break; + break; case 'double': if (is_finite($value)) { // database can not handle INF and NAN switch ($type) { @@ -225,7 +220,7 @@ public function processModifier(string $type, $value): string } } - break; + break; case 'boolean': switch ($type) { case 'any': @@ -238,7 +233,7 @@ public function processModifier(string $type, $value): string return $this->driver->convertJsonToSql($value); } - break; + break; case 'NULL': switch ($type) { case 'any': @@ -254,7 +249,7 @@ public function processModifier(string $type, $value): string return 'NULL'; } - break; + break; case 'object': if ($type === 'json' || $type === '?json') { return $this->driver->convertJsonToSql($value); @@ -296,7 +291,7 @@ public function processModifier(string $type, $value): string } } - break; + break; case 'array': switch ($type) { // micro-optimizations @@ -387,7 +382,7 @@ public function processModifier(string $type, $value): string /** - * @param mixed $value + * @param mixed $value * @phpstan-return never */ protected function throwInvalidValueTypeException(string $type, $value, string $expectedType): void @@ -398,7 +393,7 @@ protected function throwInvalidValueTypeException(string $type, $value, string $ /** - * @param mixed $value + * @param mixed $value * @phpstan-return never */ protected function throwWrongModifierException(string $type, $value, string $hint): void @@ -548,13 +543,13 @@ private function processMultiColumnOr(array $values): string foreach ($values as $value) { $sqls[] = $this->processWhere('and', $value); } - return '(' . implode(') OR (', $sqls) . ')'; + return '(' . implode(') OR (', $sqls) . ')'; } } /** - * @param mixed $value + * @param mixed $value * @return float|string */ protected function getVariableTypeName($value) diff --git a/src/Utils/DateTimeImmutable.php b/src/Utils/DateTimeImmutable.php index 6d1b661b..9e135607 100644 --- a/src/Utils/DateTimeImmutable.php +++ b/src/Utils/DateTimeImmutable.php @@ -1,11 +1,5 @@