diff --git a/src/DatabaseManager.php b/src/DatabaseManager.php index 034e753e..fe931d69 100644 --- a/src/DatabaseManager.php +++ b/src/DatabaseManager.php @@ -161,7 +161,7 @@ public function driver(string $driver): DriverInterface if ($driverObject instanceof LoggerAwareInterface) { $logger = $this->getLoggerForDriver($driverObject); - if (! $logger instanceof NullLogger) { + if (!$logger instanceof NullLogger) { $driverObject->setLogger($logger); } } @@ -200,7 +200,7 @@ private function makeDatabase(DatabasePartial $database): Database private function getLoggerForDriver(DriverInterface $driver): LoggerInterface { - if (! $this->loggerFactory) { + if (!$this->loggerFactory) { return $this->logger ??= new NullLogger(); } diff --git a/src/Driver/Jsoner.php b/src/Driver/Jsoner.php index 8211e4b4..4c4a07e2 100644 --- a/src/Driver/Jsoner.php +++ b/src/Driver/Jsoner.php @@ -27,7 +27,7 @@ final class Jsoner public static function toJson(mixed $value, bool $encode = true, bool $validate = true): string { if ($encode) { - return \json_encode($value, \JSON_UNESCAPED_UNICODE|\JSON_THROW_ON_ERROR); + return \json_encode($value, \JSON_UNESCAPED_UNICODE | \JSON_THROW_ON_ERROR); } $result = (string)$value; diff --git a/src/Driver/MySQL/Schema/MySQLColumn.php b/src/Driver/MySQL/Schema/MySQLColumn.php index da74d081..4bae5085 100644 --- a/src/Driver/MySQL/Schema/MySQLColumn.php +++ b/src/Driver/MySQL/Schema/MySQLColumn.php @@ -78,7 +78,7 @@ class MySQLColumn extends AbstractColumn //bigInteger 'integer' => ['type' => 'int', 'size' => 11, 'unsigned' => false, 'zerofill' => false], 'tinyInteger' => ['type' => 'tinyint', 'size' => 4, 'unsigned' => false, 'zerofill' => false], - 'smallInteger'=> ['type' => 'smallint', 'size' => 6, 'unsigned' => false, 'zerofill' => false], + 'smallInteger' => ['type' => 'smallint', 'size' => 6, 'unsigned' => false, 'zerofill' => false], 'bigInteger' => ['type' => 'bigint', 'size' => 20, 'unsigned' => false, 'zerofill' => false], //String with specified length (mapped via method) @@ -121,7 +121,7 @@ class MySQLColumn extends AbstractColumn 'boolean' => ['bool', 'boolean', ['type' => 'tinyint', 'size' => 1]], 'integer' => ['int', 'integer', 'mediumint'], 'tinyInteger' => ['tinyint'], - 'smallInteger'=> ['smallint'], + 'smallInteger' => ['smallint'], 'bigInteger' => ['bigint'], 'string' => ['varchar', 'char'], 'text' => ['text', 'mediumtext'], diff --git a/src/Driver/SQLServer/SQLServerDriver.php b/src/Driver/SQLServer/SQLServerDriver.php index 2f785fdb..88a99726 100644 --- a/src/Driver/SQLServer/SQLServerDriver.php +++ b/src/Driver/SQLServer/SQLServerDriver.php @@ -57,7 +57,7 @@ protected function bindParameters( $index++; } - $type = \PDO::PARAM_STR; + $type = PDO::PARAM_STR; if ($parameter instanceof ParameterInterface) { $type = $parameter->getType(); @@ -74,14 +74,14 @@ protected function bindParameters( $parameter = $this->formatDatetime($parameter); } - if ($type === \PDO::PARAM_LOB) { + if ($type === PDO::PARAM_LOB) { /** @psalm-suppress UndefinedConstant */ $statement->bindParam( $index, $parameter, $type, 0, - \PDO::SQLSRV_ENCODING_BINARY + PDO::SQLSRV_ENCODING_BINARY ); unset($parameter); @@ -181,7 +181,7 @@ public static function create(DriverConfig $config): static ) ); - if ((int) $driver->getPDO()->getAttribute(\PDO::ATTR_SERVER_VERSION) < 12) { + if ((int) $driver->getPDO()->getAttribute(PDO::ATTR_SERVER_VERSION) < 12) { throw new DriverException('SQLServer driver supports only 12+ version of SQLServer'); } diff --git a/src/Driver/SQLServer/Schema/SQLServerColumn.php b/src/Driver/SQLServer/Schema/SQLServerColumn.php index ed8fd589..10339b4b 100644 --- a/src/Driver/SQLServer/Schema/SQLServerColumn.php +++ b/src/Driver/SQLServer/Schema/SQLServerColumn.php @@ -65,7 +65,7 @@ class SQLServerColumn extends AbstractColumn //bigInteger 'integer' => 'int', 'tinyInteger' => 'tinyint', - 'smallInteger'=> 'smallint', + 'smallInteger' => 'smallint', 'bigInteger' => 'bigint', //String with specified length (mapped via method) @@ -107,7 +107,7 @@ class SQLServerColumn extends AbstractColumn 'boolean' => ['bit'], 'integer' => ['int'], 'tinyInteger' => ['tinyint'], - 'smallInteger'=> ['smallint'], + 'smallInteger' => ['smallint'], 'bigInteger' => ['bigint'], 'text' => [['type' => 'varchar', 'size' => 0]], 'string' => ['varchar', 'char'], diff --git a/src/Driver/SQLite/Schema/SQLiteColumn.php b/src/Driver/SQLite/Schema/SQLiteColumn.php index b886ddd3..72d3744d 100644 --- a/src/Driver/SQLite/Schema/SQLiteColumn.php +++ b/src/Driver/SQLite/Schema/SQLiteColumn.php @@ -55,7 +55,7 @@ class SQLiteColumn extends AbstractColumn //bigInteger 'integer' => 'integer', 'tinyInteger' => 'tinyint', - 'smallInteger'=> 'smallint', + 'smallInteger' => 'smallint', 'bigInteger' => 'bigint', //String with specified length (mapped via method) @@ -95,7 +95,7 @@ class SQLiteColumn extends AbstractColumn 'boolean' => ['boolean'], 'integer' => ['int', 'integer', 'mediumint'], 'tinyInteger' => ['tinyint'], - 'smallInteger'=> ['smallint'], + 'smallInteger' => ['smallint'], 'bigInteger' => ['bigint'], 'text' => ['text', 'string'], 'double' => ['double'], diff --git a/src/Injection/Alias.php b/src/Injection/Alias.php new file mode 100644 index 00000000..c0d7bc19 --- /dev/null +++ b/src/Injection/Alias.php @@ -0,0 +1,66 @@ +sqlStatement($parameters); + + return new static($statement . ' AS ' . $alias, $parameters->getParameters()); + } + + /** + * @param non-empty-string $alias + */ + public static function value(string $alias, mixed $value): static + { + return new static($value . ' AS ' . $alias, [$value]); + } + + /** + * @param non-empty-string $alias + */ + public static function fragment(string $alias, FragmentInterface $fragment): static + { + $tokens = $fragment->getTokens(); + + return new static($tokens['fragment'] . ' AS ' . $alias, $tokens['parameters']); + } +} diff --git a/src/Injection/Expression.php b/src/Injection/Expression.php index ef02c46d..2e2b9ac5 100644 --- a/src/Injection/Expression.php +++ b/src/Injection/Expression.php @@ -18,7 +18,7 @@ * table and column names. This class will quote and prefix every found table name and column while * query compilation. * - * Example: new SQLExpression("table.column = table.column + 1"); + * Example: new Expression("table.column = table.column + 1"); * * I potentially should have an interface for such class. */ diff --git a/src/Injection/Fragment.php b/src/Injection/Fragment.php index 82aa3e9e..b073861e 100644 --- a/src/Injection/Fragment.php +++ b/src/Injection/Fragment.php @@ -14,10 +14,10 @@ use Cycle\Database\Driver\CompilerInterface; /** - * Default implementation of SQLFragmentInterface, provides ability to inject custom SQL code into + * Default implementation of FragmentInterface, provides ability to inject custom SQL code into * query builders. Usually used to mock database specific functions. * - * Example: ...->where('time_created', '>', new SQLFragment("NOW()")); + * Example: ...->where('time_created', '>', new Fragment("NOW()")); */ class Fragment implements FragmentInterface, \Stringable { diff --git a/src/Schema/AbstractColumn.php b/src/Schema/AbstractColumn.php index 9f29a760..ef2121bb 100644 --- a/src/Schema/AbstractColumn.php +++ b/src/Schema/AbstractColumn.php @@ -102,7 +102,7 @@ abstract class AbstractColumn implements ColumnInterface, ElementInterface //bigInteger 'integer' => null, 'tinyInteger' => null, - 'smallInteger'=> null, + 'smallInteger' => null, 'bigInteger' => null, //String with specified length (mapped via method) @@ -149,7 +149,7 @@ abstract class AbstractColumn implements ColumnInterface, ElementInterface 'boolean' => [], 'integer' => [], 'tinyInteger' => [], - 'smallInteger'=> [], + 'smallInteger' => [], 'bigInteger' => [], 'string' => [], 'text' => [], diff --git a/tests/Database/Functional/Driver/Common/BaseTest.php b/tests/Database/Functional/Driver/Common/BaseTest.php index 626ec77a..6fa151cc 100644 --- a/tests/Database/Functional/Driver/Common/BaseTest.php +++ b/tests/Database/Functional/Driver/Common/BaseTest.php @@ -51,7 +51,7 @@ private function getDriver(array $driverConfig = [], array $connectionConfig = [ { $hash = \hash('crc32', static::DRIVER . ':' . \json_encode($driverConfig) . \json_encode($connectionConfig)); - if (! isset(self::$memoizedDrivers[$hash])) { + if (!isset(self::$memoizedDrivers[$hash])) { $config = clone self::$config[static::DRIVER]; assert($config instanceof DriverConfig);