From fe45552372d14d7c5d3435d899640a62be8885f3 Mon Sep 17 00:00:00 2001 From: Aleksei Gagarin Date: Fri, 3 Sep 2021 13:17:31 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/ColumnInterface.php | 6 +- src/Config/DatabaseConfig.php | 17 +- src/Config/DatabasePartial.php | 4 +- src/Database.php | 7 +- src/DatabaseInterface.php | 24 ++- src/DatabaseManager.php | 22 ++- src/DatabaseProviderInterface.php | 3 +- src/Driver/CachingCompilerInterface.php | 1 + src/Driver/Compiler.php | 21 +- src/Driver/CompilerCache.php | 7 + src/Driver/CompilerInterface.php | 8 +- src/Driver/Driver.php | 62 +++--- src/Driver/DriverInterface.php | 8 +- src/Driver/Handler.php | 10 +- src/Driver/HandlerInterface.php | 25 ++- src/Driver/MySQL/MySQLCompiler.php | 1 + src/Driver/MySQL/MySQLDriver.php | 6 +- src/Driver/MySQL/MySQLHandler.php | 3 +- src/Driver/MySQL/Schema/MySQLColumn.php | 100 +++++----- src/Driver/MySQL/Schema/MySQLForeignKey.php | 1 + src/Driver/MySQL/Schema/MySQLIndex.php | 1 + src/Driver/MySQL/Schema/MySQLTable.php | 7 +- src/Driver/Postgres/PostgresCompiler.php | 2 + src/Driver/Postgres/PostgresDriver.php | 6 +- .../Postgres/Query/PostgresInsertQuery.php | 8 +- .../Postgres/Query/PostgresSelectQuery.php | 5 +- src/Driver/Postgres/Schema/PostgresColumn.php | 98 +++++----- .../Postgres/Schema/PostgresForeignKey.php | 2 + src/Driver/Postgres/Schema/PostgresIndex.php | 1 + src/Driver/Postgres/Schema/PostgresTable.php | 1 + src/Driver/Quoter.php | 10 +- src/Driver/SQLServer/SQLServerDriver.php | 9 +- src/Driver/SQLServer/SQLServerHandler.php | 2 +- .../SQLServer/Schema/SQLServerColumn.php | 82 ++++---- .../SQLServer/Schema/SQLServerIndex.php | 3 +- .../SQLServer/Schema/SQlServerForeignKey.php | 1 + src/Driver/SQLite/SQLiteHandler.php | 5 + src/Driver/SQLite/Schema/SQLiteColumn.php | 83 ++++---- src/Driver/SQLite/Schema/SQLiteForeignKey.php | 2 + src/Driver/SQLite/Schema/SQLiteIndex.php | 5 +- src/Driver/SQLite/Schema/SQLiteTable.php | 4 +- src/Driver/Statement.php | 1 + src/ForeignKeyInterface.php | 2 +- src/Injection/Expression.php | 5 +- src/Injection/Fragment.php | 7 +- src/Injection/Parameter.php | 4 +- src/Injection/ParameterInterface.php | 2 +- src/Query/ActiveQuery.php | 12 +- src/Query/BuilderInterface.php | 7 +- src/Query/DeleteQuery.php | 5 +- src/Query/InsertQuery.php | 14 +- src/Query/Interpolator.php | 3 + src/Query/QueryBuilder.php | 7 +- src/Query/QueryInterface.php | 1 + src/Query/SelectQuery.php | 99 ++++++---- src/Query/Traits/HavingTrait.php | 10 +- src/Query/Traits/JoinTrait.php | 70 ++++--- src/Query/Traits/TokenTrait.php | 13 +- src/Query/Traits/WhereTrait.php | 10 +- src/Query/UpdateQuery.php | 19 +- src/Schema/AbstractColumn.php | 185 ++++++++++-------- src/Schema/AbstractForeignKey.php | 18 +- src/Schema/AbstractIndex.php | 25 ++- src/Schema/AbstractTable.php | 65 +++--- src/Schema/Reflector.php | 2 +- src/Schema/State.php | 17 +- src/Schema/Traits/ElementTrait.php | 4 +- src/StatementInterface.php | 3 + src/Table.php | 8 +- src/TableInterface.php | 3 + tests/Database/BaseTest.php | 15 +- tests/Database/ConfigTest.php | 108 +++++----- tests/Database/ConsistencyTest.php | 8 +- tests/Database/DatabaseTest.php | 1 - .../Postgres/AlterColumnsWithSchemaTest.php | 2 +- .../Driver/Postgres/CreateTableWithSchema.php | 2 +- tests/Database/Driver/Postgres/DriverTest.php | 44 ++--- tests/Database/Driver/Postgres/Helpers.php | 5 +- .../Driver/Postgres/InsertQueryTest.php | 3 +- tests/Database/Driver/Postgres/TableTest.php | 10 +- .../Driver/SQLServer/SelectQueryTest.php | 8 +- .../Driver/SQLServer/StatementTest.php | 10 +- tests/Database/Driver/SQLServer/TableTest.php | 4 +- .../Driver/SQLite/SelectQueryTest.php | 2 +- tests/Database/FragmentTest.php | 4 +- tests/Database/InterpolatorTest.php | 4 +- tests/Database/ManagerTest.php | 80 ++++---- tests/Database/NestedQueriesTest.php | 24 ++- tests/Database/ParameterTest.php | 2 +- tests/Database/QuoterTest.php | 1 + tests/Database/SelectQueryTest.php | 127 ++++++------ tests/Database/StatementTest.php | 8 +- tests/Database/TableTest.php | 44 ++--- tests/Database/Tokens/DeleteQueryTest.php | 6 +- tests/Database/Tokens/InsertQueryTest.php | 4 +- tests/Database/Tokens/SelectQueryTest.php | 22 +-- tests/Database/Tokens/UpdateQueryTest.php | 12 +- tests/Database/Traits/TableAssertions.php | 1 - tests/Database/UpdateQueryTest.php | 14 +- tests/bootstrap.php | 50 ++--- tests/generate.php | 16 +- 101 files changed, 1081 insertions(+), 854 deletions(-) diff --git a/src/ColumnInterface.php b/src/ColumnInterface.php index ae1f2b43..03f8edd7 100644 --- a/src/ColumnInterface.php +++ b/src/ColumnInterface.php @@ -19,10 +19,10 @@ interface ColumnInterface /** * PHP types for phpType() method. */ - public const INT = 'int'; - public const BOOL = 'bool'; + public const INT = 'int'; + public const BOOL = 'bool'; public const STRING = 'string'; - public const FLOAT = 'float'; + public const FLOAT = 'float'; /** * Get element name (unquoted). diff --git a/src/Config/DatabaseConfig.php b/src/Config/DatabaseConfig.php index 78edbcf2..f0937466 100644 --- a/src/Config/DatabaseConfig.php +++ b/src/Config/DatabaseConfig.php @@ -20,17 +20,18 @@ final class DatabaseConfig extends InjectableConfig { use AliasTrait; - public const CONFIG = 'database'; + public const CONFIG = 'database'; public const DEFAULT_DATABASE = 'default'; /** * @internal + * * @var array */ protected $config = [ - 'default' => self::DEFAULT_DATABASE, - 'aliases' => [], - 'databases' => [], + 'default' => self::DEFAULT_DATABASE, + 'aliases' => [], + 'databases' => [], 'connections' => [], ]; @@ -74,6 +75,7 @@ public function getDrivers(): array /** * @param string $database + * * @return bool */ public function hasDatabase(string $database): bool @@ -83,9 +85,10 @@ public function hasDatabase(string $database): bool /** * @param string $database - * @return DatabasePartial * * @throws ConfigException + * + * @return DatabasePartial */ public function getDatabase(string $database): DatabasePartial { @@ -105,6 +108,7 @@ public function getDatabase(string $database): DatabasePartial /** * @param string $driver + * * @return bool */ public function hasDriver(string $driver): bool @@ -114,9 +118,10 @@ public function hasDriver(string $driver): bool /** * @param string $driver - * @return Autowire * * @throws ConfigException + * + * @return Autowire */ public function getDriver(string $driver): Autowire { diff --git a/src/Config/DatabasePartial.php b/src/Config/DatabasePartial.php index 0ce10482..be34eda5 100644 --- a/src/Config/DatabasePartial.php +++ b/src/Config/DatabasePartial.php @@ -22,7 +22,7 @@ final class DatabasePartial /** @var string */ private $driver; - /** @var null|string */ + /** @var string|null */ private $readDriver; /** @@ -68,7 +68,7 @@ public function getDriver(): string } /** - * @return null|string + * @return string|null */ public function getReadDriver(): ?string { diff --git a/src/Database.php b/src/Database.php index e77c362b..ca73a83d 100644 --- a/src/Database.php +++ b/src/Database.php @@ -28,9 +28,9 @@ final class Database implements DatabaseInterface, InjectableInterface public const INJECTOR = DatabaseManager::class; // Isolation levels for transactions - public const ISOLATION_SERIALIZABLE = DriverInterface::ISOLATION_SERIALIZABLE; - public const ISOLATION_REPEATABLE_READ = DriverInterface::ISOLATION_REPEATABLE_READ; - public const ISOLATION_READ_COMMITTED = DriverInterface::ISOLATION_READ_COMMITTED; + public const ISOLATION_SERIALIZABLE = DriverInterface::ISOLATION_SERIALIZABLE; + public const ISOLATION_REPEATABLE_READ = DriverInterface::ISOLATION_REPEATABLE_READ; + public const ISOLATION_READ_COMMITTED = DriverInterface::ISOLATION_READ_COMMITTED; public const ISOLATION_READ_UNCOMMITTED = DriverInterface::ISOLATION_READ_UNCOMMITTED; /** @var string */ @@ -68,6 +68,7 @@ public function __construct( * Shortcut to get table abstraction. * * @param string $name Table name without prefix. + * * @return Table */ public function __get(string $name): Table diff --git a/src/DatabaseInterface.php b/src/DatabaseInterface.php index 2789d768..c3858bc1 100644 --- a/src/DatabaseInterface.php +++ b/src/DatabaseInterface.php @@ -27,7 +27,7 @@ interface DatabaseInterface { // Driver types public const WRITE = 0; - public const READ = 1; + public const READ = 1; /** * @return string @@ -44,6 +44,7 @@ public function getType(): string; /** * @param int $type + * * @return DriverInterface */ public function getDriver(int $type = self::WRITE): DriverInterface; @@ -53,7 +54,8 @@ public function getDriver(int $type = self::WRITE): DriverInterface; * * @param string $prefix * @param bool $add - * @return self|$this + * + * @return $this|self */ public function withPrefix(string $prefix, bool $add = true): self; @@ -66,6 +68,7 @@ public function getPrefix(): string; * Check if table exists. * * @param string $name + * * @return bool */ public function hasTable(string $name): bool; @@ -79,6 +82,7 @@ public function getTables(): array; /** * @param string $name + * * @return TableInterface */ public function table(string $name): TableInterface; @@ -88,9 +92,10 @@ public function table(string $name): TableInterface; * * @param string $query * @param array $parameters Parameters to be binded into query. - * @return int * * @throws StatementException + * + * @return int */ public function execute(string $query, array $parameters = []): int; @@ -99,9 +104,10 @@ public function execute(string $query, array $parameters = []): int; * * @param string $query * @param array $parameters Parameters to be binded into query. - * @return StatementInterface * * @throws StatementException + * + * @return StatementInterface */ public function query(string $query, array $parameters = []): StatementInterface; @@ -109,6 +115,7 @@ public function query(string $query, array $parameters = []): StatementInterface * Get instance of InsertBuilder associated with current Database. * * @param string $table Table where values should be inserted to. + * * @return InsertQuery */ public function insert(string $table = ''): InsertQuery; @@ -119,6 +126,7 @@ public function insert(string $table = ''): InsertQuery; * @param string $table Table where rows should be updated in. * @param array $values Initial set of columns to update associated with their values. * @param array $where Initial set of where rules specified as array. + * * @return UpdateQuery */ public function update(string $table = '', array $values = [], array $where = []): UpdateQuery; @@ -128,6 +136,7 @@ public function update(string $table = '', array $values = [], array $where = [] * * @param string $table Table where rows should be deleted from. * @param array $where Initial set of where rules specified as array. + * * @return DeleteQuery */ public function delete(string $table = '', array $where = []): DeleteQuery; @@ -136,6 +145,7 @@ public function delete(string $table = '', array $where = []): DeleteQuery; * Get instance of SelectBuilder associated with current Database. * * @param array|string $columns Columns to select. + * * @return SelectQuery */ public function select($columns = '*'): SelectQuery; @@ -145,11 +155,13 @@ public function select($columns = '*'): SelectQuery; * function must receive only one argument - DatabaseInterface instance. * * @link http://en.wikipedia.org/wiki/Database_transaction + * * @param callable $callback * @param string $isolationLevel - * @return mixed * * @throws \Throwable + * + * @return mixed */ public function transaction(callable $callback, string $isolationLevel = null); @@ -157,7 +169,9 @@ public function transaction(callable $callback, string $isolationLevel = null); * Start database transaction. * * @link http://en.wikipedia.org/wiki/Database_transaction + * * @param string $isolationLevel + * * @return bool */ public function begin(string $isolationLevel = null): bool; diff --git a/src/DatabaseManager.php b/src/DatabaseManager.php index 2ba3ab1e..c3dd4e3d 100644 --- a/src/DatabaseManager.php +++ b/src/DatabaseManager.php @@ -142,9 +142,9 @@ public function createInjection(\ReflectionClass $class, string $context = null) /** * Get all databases. * - * @return Database[] - * * @throws DatabaseException + * + * @return Database[] */ public function getDatabases(): array { @@ -167,9 +167,10 @@ public function getDatabases(): array * Get Database associated with a given database alias or automatically created one. * * @param string|null $database - * @return Database|DatabaseInterface * * @throws DBALException + * + * @return Database|DatabaseInterface */ public function database(string $database = null): DatabaseInterface { @@ -214,9 +215,9 @@ public function addDatabase(Database $database): void /** * Get instance of every available driver/connection. * - * @return Driver[] - * * @throws DBALException + * + * @return Driver[] */ public function getDrivers(): array { @@ -239,9 +240,10 @@ public function getDrivers(): array * Get driver instance by it's name or automatically create one. * * @param string $driver - * @return DriverInterface * * @throws DBALException + * + * @return DriverInterface */ public function driver(string $driver): DriverInterface { @@ -271,11 +273,12 @@ public function driver(string $driver): DriverInterface * * @param string $name * @param DriverInterface $driver - * @return self * * @throws DBALException + * + * @return self */ - public function addDriver(string $name, DriverInterface $driver): DatabaseManager + public function addDriver(string $name, DriverInterface $driver): self { if (isset($this->drivers[$name])) { throw new DBALException("Connection '{$name}' already exists"); @@ -288,9 +291,10 @@ public function addDriver(string $name, DriverInterface $driver): DatabaseManage /** * @param DatabasePartial $database - * @return Database * * @throws DBALException + * + * @return Database */ protected function makeDatabase(DatabasePartial $database): Database { diff --git a/src/DatabaseProviderInterface.php b/src/DatabaseProviderInterface.php index 2492d243..94bebd83 100644 --- a/src/DatabaseProviderInterface.php +++ b/src/DatabaseProviderInterface.php @@ -19,9 +19,10 @@ interface DatabaseProviderInterface * Get Database associated with a given database alias or automatically created one. * * @param string|null $database - * @return DatabaseInterface * * @throws DBALException + * + * @return DatabaseInterface */ public function database(string $database = null): DatabaseInterface; } diff --git a/src/Driver/CachingCompilerInterface.php b/src/Driver/CachingCompilerInterface.php index 674eb4a0..e5a968f4 100644 --- a/src/Driver/CachingCompilerInterface.php +++ b/src/Driver/CachingCompilerInterface.php @@ -23,6 +23,7 @@ interface CachingCompilerInterface extends CompilerInterface * * @param QueryParameters $params * @param array $tokens + * * @return string */ public function hashLimit(QueryParameters $params, array $tokens): string; diff --git a/src/Driver/Compiler.php b/src/Driver/Compiler.php index 38314db3..fbe2fa8f 100644 --- a/src/Driver/Compiler.php +++ b/src/Driver/Compiler.php @@ -35,6 +35,7 @@ public function __construct(string $quotes = '""') /** * @param string $identifier + * * @return string */ public function quoteIdentifier(string $identifier): string @@ -46,6 +47,7 @@ public function quoteIdentifier(string $identifier): string * @param QueryParameters $params * @param string $prefix * @param FragmentInterface $fragment + * * @return string */ public function compile( @@ -82,6 +84,7 @@ public function hashLimit(QueryParameters $params, array $tokens): string * @param Quoter $q * @param FragmentInterface $fragment * @param bool $nestedQuery + * * @return string */ protected function fragment( @@ -146,6 +149,7 @@ protected function fragment( * @param QueryParameters $params * @param Quoter $q * @param array $tokens + * * @return string */ protected function insertQuery(QueryParameters $params, Quoter $q, array $tokens): string @@ -174,6 +178,7 @@ protected function insertQuery(QueryParameters $params, Quoter $q, array $tokens * @param QueryParameters $params * @param Quoter $q * @param array $tokens + * * @return string */ protected function selectQuery(QueryParameters $params, Quoter $q, array $tokens): string @@ -206,6 +211,7 @@ protected function selectQuery(QueryParameters $params, Quoter $q, array $tokens * @param QueryParameters $params * @param Quoter $q * @param bool|string $distinct + * * @return string */ protected function distinct(QueryParameters $params, Quoter $q, $distinct): string @@ -221,6 +227,7 @@ protected function distinct(QueryParameters $params, Quoter $q, $distinct): stri * @param QueryParameters $params * @param Quoter $q * @param array $joins + * * @return string */ protected function joins(QueryParameters $params, Quoter $q, array $joins): string @@ -252,6 +259,7 @@ protected function joins(QueryParameters $params, Quoter $q, array $joins): stri * @param QueryParameters $params * @param Quoter $q * @param array $unions + * * @return string */ protected function unions(QueryParameters $params, Quoter $q, array $unions): string @@ -280,6 +288,7 @@ protected function unions(QueryParameters $params, Quoter $q, array $unions): st * @param QueryParameters $params * @param Quoter $q * @param array $orderBy + * * @return string */ protected function orderBy(QueryParameters $params, Quoter $q, array $orderBy): string @@ -304,13 +313,14 @@ protected function orderBy(QueryParameters $params, Quoter $q, array $orderBy): * @param QueryParameters $params * @param Quoter $q * @param array $groupBy + * * @return string */ protected function groupBy(QueryParameters $params, Quoter $q, array $groupBy): string { $result = []; foreach ($groupBy as $identifier) { - $result[] = $this->name($params, $q, $identifier); + $result[] = $this->name($params, $q, $identifier); } return implode(', ', $result); @@ -321,6 +331,7 @@ protected function groupBy(QueryParameters $params, Quoter $q, array $groupBy): * @param Quoter $q * @param int|null $limit * @param int|null $offset + * * @return string */ abstract protected function limit( @@ -334,6 +345,7 @@ abstract protected function limit( * @param QueryParameters $parameters * @param Quoter $quoter * @param array $tokens + * * @return string */ protected function updateQuery( @@ -362,6 +374,7 @@ protected function updateQuery( * @param QueryParameters $parameters * @param Quoter $quoter * @param array $tokens + * * @return string */ protected function deleteQuery( @@ -384,6 +397,7 @@ protected function deleteQuery( * @param Quoter $q * @param mixed $name * @param bool $table + * * @return string */ protected function name(QueryParameters $params, Quoter $q, $name, bool $table = false): string @@ -404,6 +418,7 @@ protected function name(QueryParameters $params, Quoter $q, $name, bool $table = * @param Quoter $q * @param array $columns * @param int $maxLength + * * @return string */ protected function columns(QueryParameters $params, Quoter $q, array $columns, int $maxLength = 180): string @@ -423,6 +438,7 @@ function ($column) use ($params, $q) { * @param QueryParameters $params * @param Quoter $q * @param mixed $value + * * @return string */ protected function value(QueryParameters $params, Quoter $q, $value): string @@ -455,6 +471,7 @@ protected function value(QueryParameters $params, Quoter $q, $value): string * @param QueryParameters $params * @param Quoter $q * @param array $tokens + * * @return string */ protected function where(QueryParameters $params, Quoter $q, array $tokens): string @@ -521,6 +538,7 @@ protected function where(QueryParameters $params, Quoter $q, array $tokens): str * @param QueryParameters $params * @param Quoter $q * @param array $context + * * @return string */ protected function condition(QueryParameters $params, Quoter $q, array $context): string @@ -581,6 +599,7 @@ protected function condition(QueryParameters $params, Quoter $q, array $context) * @param string $prefix * @param string $expression * @param string $postfix + * * @return string */ protected function optional(string $prefix, string $expression, string $postfix = ''): string diff --git a/src/Driver/CompilerCache.php b/src/Driver/CompilerCache.php index 88a3531c..b08e7020 100644 --- a/src/Driver/CompilerCache.php +++ b/src/Driver/CompilerCache.php @@ -41,6 +41,7 @@ public function __construct(CachingCompilerInterface $compiler) /** * @param string $identifier + * * @return string */ public function quoteIdentifier(string $identifier): string @@ -52,6 +53,7 @@ public function quoteIdentifier(string $identifier): string * @param QueryParameters $params * @param string $prefix * @param FragmentInterface $fragment + * * @return string */ public function compile(QueryParameters $params, string $prefix, FragmentInterface $fragment): string @@ -97,6 +99,7 @@ public function compile(QueryParameters $params, string $prefix, FragmentInterfa /** * @param QueryParameters $params * @param array $tokens + * * @return string */ protected function hashInsertQuery(QueryParameters $params, array $tokens): string @@ -145,6 +148,7 @@ protected function hashInsertQuery(QueryParameters $params, array $tokens): stri /** * @param QueryParameters $params * @param array $tokens + * * @return string */ protected function hashSelectQuery(QueryParameters $params, array $tokens): string @@ -214,6 +218,7 @@ protected function hashSelectQuery(QueryParameters $params, array $tokens): stri /** * @param QueryParameters $params * @param array $where + * * @return string */ protected function hashWhere(QueryParameters $params, array $where): string @@ -303,6 +308,7 @@ protected function hashWhere(QueryParameters $params, array $where): string /** * @param QueryParameters $params * @param array $columns + * * @return string */ protected function hashColumns(QueryParameters $params, array $columns): string @@ -324,6 +330,7 @@ protected function hashColumns(QueryParameters $params, array $columns): string /** * @param QueryParameters $params * @param ParameterInterface $param + * * @return string */ private function hashParam(QueryParameters $params, ParameterInterface $param): string diff --git a/src/Driver/CompilerInterface.php b/src/Driver/CompilerInterface.php index 322a96c7..8c7604d8 100644 --- a/src/Driver/CompilerInterface.php +++ b/src/Driver/CompilerInterface.php @@ -17,18 +17,19 @@ interface CompilerInterface { // indicates the fragment type to be handled by query compiler - public const FRAGMENT = 1; - public const EXPRESSION = 2; + public const FRAGMENT = 1; + public const EXPRESSION = 2; public const INSERT_QUERY = 4; public const SELECT_QUERY = 5; public const UPDATE_QUERY = 6; public const DELETE_QUERY = 7; public const TOKEN_AND = '@AND'; - public const TOKEN_OR = '@OR'; + public const TOKEN_OR = '@OR'; /** * @param string $identifier + * * @return string */ public function quoteIdentifier(string $identifier): string; @@ -39,6 +40,7 @@ public function quoteIdentifier(string $identifier): string; * @param QueryParameters $params * @param string $prefix * @param FragmentInterface $fragment + * * @return string */ public function compile( diff --git a/src/Driver/Driver.php b/src/Driver/Driver.php index 96ff739f..2dbba837 100644 --- a/src/Driver/Driver.php +++ b/src/Driver/Driver.php @@ -38,8 +38,8 @@ abstract class Driver implements DriverInterface, LoggerAwareInterface // Driver specific PDO options protected const DEFAULT_PDO_OPTIONS = [ - PDO::ATTR_CASE => PDO::CASE_NATURAL, - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_CASE => PDO::CASE_NATURAL, + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false, ]; @@ -51,25 +51,25 @@ abstract class Driver implements DriverInterface, LoggerAwareInterface */ protected $options = [ // allow reconnects - 'reconnect' => true, + 'reconnect' => true, // all datetime objects will be converted relative to // this timezone (must match with DB timezone!) - 'timezone' => 'UTC', + 'timezone' => 'UTC', // DSN - 'connection' => '', - 'username' => '', - 'password' => '', + 'connection' => '', + 'username' => '', + 'password' => '', // pdo options - 'options' => [], + 'options' => [], // enables query caching - 'queryCache' => true, + 'queryCache' => true, // disable schema modifications - 'readonlySchema' => false + 'readonlySchema' => false, ]; /** @var PDO|null */ @@ -135,10 +135,10 @@ public function __destruct() public function __debugInfo() { return [ - 'addr' => $this->getDSN(), - 'source' => $this->getSource(), + 'addr' => $this->getDSN(), + 'source' => $this->getSource(), 'connected' => $this->isConnected(), - 'options' => $this->options['options'], + 'options' => $this->options['options'], ]; } @@ -147,13 +147,14 @@ public function __debugInfo() * * @param string $name * @param array $arguments + * * @return mixed * * @deprecated this method will be removed in a future releases. */ public function __call(string $name, array $arguments): mixed { - return match($name) { + return match ($name) { 'isProfiling' => true, 'setProfiling' => null, 'getSchema' => $this->getSchemaHandler()->getSchema( @@ -180,9 +181,9 @@ public function __call(string $name, array $arguments): mixed /** * Get driver source database or file name. * - * @return string - * * @throws DriverException + * + * @return string */ public function getSource(): string { @@ -282,9 +283,10 @@ public function quote($value, int $type = PDO::PARAM_STR): string * * @param string $statement * @param array $parameters - * @return StatementInterface * * @throws StatementException + * + * @return StatementInterface */ public function query(string $statement, array $parameters = []): StatementInterface { @@ -296,9 +298,10 @@ public function query(string $statement, array $parameters = []): StatementInter * * @param string $query * @param array $parameters - * @return int * * @throws StatementException + * + * @return int */ public function execute(string $query, array $parameters = []): int { @@ -310,6 +313,7 @@ public function execute(string $query, array $parameters = []): int * such functionality may not work in some DBMS property (Postgres). * * @param string|null $sequence Name of the sequence object from which the ID should be returned. + * * @return mixed */ public function lastInsertID(string $sequence = null) @@ -328,6 +332,7 @@ public function lastInsertID(string $sequence = null) * @link http://en.wikipedia.org/wiki/Isolation_(database_systems) * * @param string|null $isolationLevel + * * @return bool */ public function beginTransaction(string $isolationLevel = null): bool @@ -373,9 +378,9 @@ public function beginTransaction(string $isolationLevel = null): bool /** * Commit the active database transaction. * - * @return bool - * * @throws StatementException + * + * @return bool */ public function commitTransaction(): bool { @@ -416,9 +421,9 @@ public function commitTransaction(): bool /** * Rollback the active database transaction. * - * @return bool - * * @throws StatementException + * + * @return bool */ public function rollbackTransaction(): bool { @@ -467,9 +472,10 @@ public function identifier(string $identifier): string * @param string $query * @param iterable $parameters * @param bool|null $retry - * @return StatementInterface * * @throws StatementException + * + * @return StatementInterface */ protected function statement( string $query, @@ -514,6 +520,7 @@ protected function statement( /** * @param string $query + * * @return PDOStatement */ protected function prepare(string $query): PDOStatement @@ -535,6 +542,7 @@ protected function prepare(string $query): PDOStatement * * @param PDOStatement $statement * @param iterable $parameters + * * @return PDOStatement */ protected function bindParameters(PDOStatement $statement, iterable $parameters): PDOStatement @@ -570,9 +578,10 @@ protected function bindParameters(PDOStatement $statement, iterable $parameters) * needed timezone. * * @param DateTimeInterface $value - * @return string * * @throws DriverException + * + * @return string */ protected function formatDatetime(DateTimeInterface $value): string { @@ -590,6 +599,7 @@ protected function formatDatetime(DateTimeInterface $value): string * * @param Throwable $exception * @param string $query + * * @return StatementException */ abstract protected function mapException( @@ -669,9 +679,9 @@ protected function createPDO(): PDO /** * Get associated PDO connection. Must automatically connect if such connection does not exists. * - * @return PDO - * * @throws DriverException + * + * @return PDO */ protected function getPDO(): PDO { diff --git a/src/Driver/DriverInterface.php b/src/Driver/DriverInterface.php index a6bb9493..06800aa7 100644 --- a/src/Driver/DriverInterface.php +++ b/src/Driver/DriverInterface.php @@ -143,6 +143,7 @@ public function disconnect(); * * @param mixed $value * @param int $type Parameter type. + * * @return string */ public function quote( @@ -155,9 +156,10 @@ public function quote( * * @param string $statement * @param array $parameters - * @return StatementInterface * * @throws StatementException + * + * @return StatementInterface */ public function query(string $statement, array $parameters = []): StatementInterface; @@ -166,9 +168,10 @@ public function query(string $statement, array $parameters = []): StatementInter * * @param string $query * @param array $parameters - * @return int * * @throws StatementException + * + * @return int */ public function execute(string $query, array $parameters = []): int; @@ -178,6 +181,7 @@ public function execute(string $query, array $parameters = []): int; * * @param string|null $sequence Name of the sequence object from which the ID should be * returned. + * * @return mixed */ public function lastInsertID(string $sequence = null); diff --git a/src/Driver/Handler.php b/src/Driver/Handler.php index 3b04dd60..177aa4ea 100644 --- a/src/Driver/Handler.php +++ b/src/Driver/Handler.php @@ -29,6 +29,7 @@ abstract class Handler implements HandlerInterface /** * @param DriverInterface $driver + * * @return HandlerInterface */ public function withDriver(DriverInterface $driver): HandlerInterface @@ -261,9 +262,10 @@ protected function executeChanges( * * @param string $statement * @param array $parameters - * @return int * * @throws HandlerException + * + * @return int */ protected function run(string $statement, array $parameters = []): int { @@ -277,7 +279,8 @@ protected function run(string $statement, array $parameters = []): int /** * Create element identifier. * - * @param ElementInterface|AbstractTable|string $element + * @param AbstractTable|ElementInterface|string $element + * * @return string */ protected function identify($element): string @@ -288,7 +291,8 @@ protected function identify($element): string if ($element instanceof AbstractTable) { return $this->driver->identifier($element->getFullName()); - } elseif ($element instanceof ElementInterface) { + } + if ($element instanceof ElementInterface) { return $this->driver->identifier($element->getName()); } diff --git a/src/Driver/HandlerInterface.php b/src/Driver/HandlerInterface.php index ff28dcab..a9297403 100644 --- a/src/Driver/HandlerInterface.php +++ b/src/Driver/HandlerInterface.php @@ -23,46 +23,48 @@ interface HandlerInterface { //Foreign key modification behaviours - public const DROP_FOREIGN_KEYS = 0b000000001; + public const DROP_FOREIGN_KEYS = 0b000000001; public const CREATE_FOREIGN_KEYS = 0b000000010; - public const ALTER_FOREIGN_KEYS = 0b000000100; + public const ALTER_FOREIGN_KEYS = 0b000000100; //All foreign keys related operations public const DO_FOREIGN_KEYS = self::DROP_FOREIGN_KEYS | self::ALTER_FOREIGN_KEYS | self::CREATE_FOREIGN_KEYS; //Column modification behaviours - public const DROP_COLUMNS = 0b000001000; + public const DROP_COLUMNS = 0b000001000; public const CREATE_COLUMNS = 0b000010000; - public const ALTER_COLUMNS = 0b000100000; + public const ALTER_COLUMNS = 0b000100000; //All columns related operations public const DO_COLUMNS = self::DROP_COLUMNS | self::ALTER_COLUMNS | self::CREATE_COLUMNS; //Index modification behaviours - public const DROP_INDEXES = 0b001000000; + public const DROP_INDEXES = 0b001000000; public const CREATE_INDEXES = 0b010000000; - public const ALTER_INDEXES = 0b100000000; + public const ALTER_INDEXES = 0b100000000; //All index related operations public const DO_INDEXES = self::DROP_INDEXES | self::ALTER_INDEXES | self::CREATE_INDEXES; //General purpose schema operations public const DO_RENAME = 0b10000000000; - public const DO_DROP = 0b01000000000; + public const DO_DROP = 0b01000000000; //All operations public const DO_ALL = self::DO_FOREIGN_KEYS | self::DO_INDEXES | self::DO_COLUMNS | self::DO_DROP | self::DO_RENAME; /** * @param DriverInterface $driver + * * @return HandlerInterface */ - public function withDriver(DriverInterface $driver): HandlerInterface; + public function withDriver(DriverInterface $driver): self; /** * Get all available table names. * * @param string|null $prefix + * * @return array */ public function getTableNames(string $prefix = ''): array; @@ -71,6 +73,7 @@ public function getTableNames(string $prefix = ''): array; * Check if given table exists in database. * * @param string $table + * * @return bool */ public function hasTable(string $table): bool; @@ -80,9 +83,10 @@ public function hasTable(string $table): bool; * * @param string $table * @param string|null $prefix - * @return AbstractTable * * @throws HandlerException + * + * @return AbstractTable */ public function getSchema(string $table, string $prefix = null): AbstractTable; @@ -90,6 +94,7 @@ public function getSchema(string $table, string $prefix = null): AbstractTable; * Create table based on a given schema. * * @param AbstractTable $table + * * @throws HandlerException */ public function createTable(AbstractTable $table): void; @@ -98,6 +103,7 @@ public function createTable(AbstractTable $table): void; * Truncate table. * * @param AbstractTable $table + * * @throws HandlerException */ public function eraseTable(AbstractTable $table): void; @@ -106,6 +112,7 @@ public function eraseTable(AbstractTable $table): void; * Drop table from database. * * @param AbstractTable $table + * * @throws HandlerException */ public function dropTable(AbstractTable $table): void; diff --git a/src/Driver/MySQL/MySQLCompiler.php b/src/Driver/MySQL/MySQLCompiler.php index 2579a49a..0827bea2 100644 --- a/src/Driver/MySQL/MySQLCompiler.php +++ b/src/Driver/MySQL/MySQLCompiler.php @@ -26,6 +26,7 @@ class MySQLCompiler extends Compiler implements CachingCompilerInterface * @param QueryParameters $params * @param Quoter $q * @param array $tokens + * * @return string */ protected function insertQuery(QueryParameters $params, Quoter $q, array $tokens): string diff --git a/src/Driver/MySQL/MySQLDriver.php b/src/Driver/MySQL/MySQLDriver.php index 6c1d510b..9ef82d8c 100644 --- a/src/Driver/MySQL/MySQLDriver.php +++ b/src/Driver/MySQL/MySQLDriver.php @@ -22,10 +22,10 @@ class MySQLDriver extends Driver { protected const DEFAULT_PDO_OPTIONS = [ - PDO::ATTR_CASE => PDO::CASE_NATURAL, - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_CASE => PDO::CASE_NATURAL, + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES "UTF8"', - PDO::ATTR_STRINGIFY_FETCHES => false, + PDO::ATTR_STRINGIFY_FETCHES => false, ]; /** diff --git a/src/Driver/MySQL/MySQLHandler.php b/src/Driver/MySQL/MySQLHandler.php index b8c61d58..a5d20292 100644 --- a/src/Driver/MySQL/MySQLHandler.php +++ b/src/Driver/MySQL/MySQLHandler.php @@ -131,9 +131,10 @@ public function dropForeignKey(AbstractTable $table, AbstractForeignKey $foreign * Get statement needed to create table. * * @param AbstractTable $table - * @return string * * @throws SchemaException + * + * @return string */ protected function createStatement(AbstractTable $table) { diff --git a/src/Driver/MySQL/Schema/MySQLColumn.php b/src/Driver/MySQL/Schema/MySQLColumn.php index a8f20884..4c590373 100644 --- a/src/Driver/MySQL/Schema/MySQLColumn.php +++ b/src/Driver/MySQL/Schema/MySQLColumn.php @@ -33,87 +33,87 @@ class MySQLColumn extends AbstractColumn */ protected $mapping = [ //Primary sequences - 'primary' => [ - 'type' => 'int', - 'size' => 11, + 'primary' => [ + 'type' => 'int', + 'size' => 11, 'autoIncrement' => true, - 'nullable' => false, + 'nullable' => false, ], - 'bigPrimary' => [ - 'type' => 'bigint', - 'size' => 20, + 'bigPrimary' => [ + 'type' => 'bigint', + 'size' => 20, 'autoIncrement' => true, - 'nullable' => false, + 'nullable' => false, ], //Enum type (mapped via method) - 'enum' => 'enum', + 'enum' => 'enum', //Logical types - 'boolean' => ['type' => 'tinyint', 'size' => 1], + 'boolean' => ['type' => 'tinyint', 'size' => 1], //Integer types (size can always be changed with size method), longInteger has method alias //bigInteger - 'integer' => ['type' => 'int', 'size' => 11], + 'integer' => ['type' => 'int', 'size' => 11], 'tinyInteger' => ['type' => 'tinyint', 'size' => 4], - 'bigInteger' => ['type' => 'bigint', 'size' => 20], + 'bigInteger' => ['type' => 'bigint', 'size' => 20], //String with specified length (mapped via method) - 'string' => ['type' => 'varchar', 'size' => 255], + 'string' => ['type' => 'varchar', 'size' => 255], //Generic types - 'text' => 'text', - 'tinyText' => 'tinytext', - 'longText' => 'longtext', + 'text' => 'text', + 'tinyText' => 'tinytext', + 'longText' => 'longtext', //Real types - 'double' => 'double', - 'float' => 'float', + 'double' => 'double', + 'float' => 'float', //Decimal type (mapped via method) - 'decimal' => 'decimal', + 'decimal' => 'decimal', //Date and Time types - 'datetime' => 'datetime', - 'date' => 'date', - 'time' => 'time', - 'timestamp' => ['type' => 'timestamp', 'defaultValue' => null], + 'datetime' => 'datetime', + 'date' => 'date', + 'time' => 'time', + 'timestamp' => ['type' => 'timestamp', 'defaultValue' => null], //Binary types - 'binary' => 'blob', - 'tinyBinary' => 'tinyblob', - 'longBinary' => 'longblob', + 'binary' => 'blob', + 'tinyBinary' => 'tinyblob', + 'longBinary' => 'longblob', //Additional types - 'json' => 'text', - 'uuid' => ['type' => 'varchar', 'size' => 36], + 'json' => 'text', + 'uuid' => ['type' => 'varchar', 'size' => 36], ]; /** * {@inheritdoc} */ protected $reverseMapping = [ - 'primary' => [['type' => 'int', 'autoIncrement' => true]], - 'bigPrimary' => ['serial', ['type' => 'bigint', 'autoIncrement' => true]], - 'enum' => ['enum'], - 'boolean' => ['bool', 'boolean', ['type' => 'tinyint', 'size' => 1]], - 'integer' => ['int', 'integer', 'smallint', 'mediumint'], + 'primary' => [['type' => 'int', 'autoIncrement' => true]], + 'bigPrimary' => ['serial', ['type' => 'bigint', 'autoIncrement' => true]], + 'enum' => ['enum'], + 'boolean' => ['bool', 'boolean', ['type' => 'tinyint', 'size' => 1]], + 'integer' => ['int', 'integer', 'smallint', 'mediumint'], 'tinyInteger' => ['tinyint'], - 'bigInteger' => ['bigint'], - 'string' => ['varchar', 'char'], - 'text' => ['text', 'mediumtext'], - 'tinyText' => ['tinytext'], - 'longText' => ['longtext'], - 'double' => ['double'], - 'float' => ['float', 'real'], - 'decimal' => ['decimal'], - 'datetime' => ['datetime'], - 'date' => ['date'], - 'time' => ['time'], - 'timestamp' => ['timestamp'], - 'binary' => ['blob', 'binary', 'varbinary'], - 'tinyBinary' => ['tinyblob'], - 'longBinary' => ['longblob'], + 'bigInteger' => ['bigint'], + 'string' => ['varchar', 'char'], + 'text' => ['text', 'mediumtext'], + 'tinyText' => ['tinytext'], + 'longText' => ['longtext'], + 'double' => ['double'], + 'float' => ['float', 'real'], + 'decimal' => ['decimal'], + 'datetime' => ['datetime'], + 'date' => ['date'], + 'time' => ['time'], + 'timestamp' => ['timestamp'], + 'binary' => ['blob', 'binary', 'varbinary'], + 'tinyBinary' => ['tinyblob'], + 'longBinary' => ['longblob'], ]; /** @@ -164,6 +164,7 @@ public function sqlStatement(DriverInterface $driver): string * @param string $table * @param array $schema * @param \DateTimeZone $timezone + * * @return MySQLColumn */ public static function createInstance( @@ -253,9 +254,10 @@ static function ($value) { * * @param string $type * @param string $value - * @return string|FragmentInterface|\DateTime * * @throws DefaultValueException + * + * @return \DateTime|FragmentInterface|string */ protected function formatDatetime(string $type, $value) { diff --git a/src/Driver/MySQL/Schema/MySQLForeignKey.php b/src/Driver/MySQL/Schema/MySQLForeignKey.php index 8fc1a932..bd92bff3 100644 --- a/src/Driver/MySQL/Schema/MySQLForeignKey.php +++ b/src/Driver/MySQL/Schema/MySQLForeignKey.php @@ -19,6 +19,7 @@ class MySQLForeignKey extends AbstractForeignKey * @param string $table * @param string $tablePrefix * @param array $schema + * * @return MySQLForeignKey */ public static function createInstance(string $table, string $tablePrefix, array $schema): self diff --git a/src/Driver/MySQL/Schema/MySQLIndex.php b/src/Driver/MySQL/Schema/MySQLIndex.php index b10985b8..5a5a6842 100644 --- a/src/Driver/MySQL/Schema/MySQLIndex.php +++ b/src/Driver/MySQL/Schema/MySQLIndex.php @@ -19,6 +19,7 @@ class MySQLIndex extends AbstractIndex * @param string $table * @param string $name * @param array $schema + * * @return MySQLIndex */ public static function createInstance(string $table, string $name, array $schema): self diff --git a/src/Driver/MySQL/Schema/MySQLTable.php b/src/Driver/MySQL/Schema/MySQLTable.php index 1e0591fe..2cb587f4 100644 --- a/src/Driver/MySQL/Schema/MySQLTable.php +++ b/src/Driver/MySQL/Schema/MySQLTable.php @@ -45,11 +45,12 @@ class MySQLTable extends AbstractTable * Change table engine. Such operation will be applied only at moment of table creation. * * @param string $engine - * @return $this * * @throws SchemaException + * + * @return $this */ - public function setEngine($engine): MySQLTable + public function setEngine($engine): self { if ($this->exists()) { throw new SchemaException('Table engine can be set only at moment of creation'); @@ -81,7 +82,7 @@ protected function initSchema(State $state): void $this->engine = $this->driver->query( 'SHOW TABLE STATUS WHERE `Name` = ?', [ - $state->getName() + $state->getName(), ] )->fetch()['Engine']; } diff --git a/src/Driver/Postgres/PostgresCompiler.php b/src/Driver/Postgres/PostgresCompiler.php index ac97dcaa..59a96fc4 100644 --- a/src/Driver/Postgres/PostgresCompiler.php +++ b/src/Driver/Postgres/PostgresCompiler.php @@ -26,6 +26,7 @@ class PostgresCompiler extends Compiler implements CachingCompilerInterface * @param QueryParameters $params * @param Quoter $q * @param array $tokens + * * @return string */ protected function insertQuery(QueryParameters $params, Quoter $q, array $tokens): string @@ -68,6 +69,7 @@ protected function distinct(QueryParameters $params, Quoter $q, $distinct): stri * @param Quoter $q * @param int|null $limit * @param int|null $offset + * * @return string */ protected function limit(QueryParameters $params, Quoter $q, int $limit = null, int $offset = null): string diff --git a/src/Driver/Postgres/PostgresDriver.php b/src/Driver/Postgres/PostgresDriver.php index 244b2318..165437f5 100644 --- a/src/Driver/Postgres/PostgresDriver.php +++ b/src/Driver/Postgres/PostgresDriver.php @@ -126,9 +126,9 @@ public function shouldUseDefinedSchemas(): bool * @param string $prefix Database prefix if any. * @param string $table Fully specified table name, including postfix. * - * @return string|null - * * @throws DriverException + * + * @return string|null */ public function getPrimaryKey(string $prefix, string $table): ?string { @@ -173,6 +173,7 @@ public function resetPrimaryKeys(): void * @link http://en.wikipedia.org/wiki/Isolation_(database_systems) * * @param string|null $isolationLevel + * * @return bool */ public function beginTransaction(string $isolationLevel = null): bool @@ -220,6 +221,7 @@ public function beginTransaction(string $isolationLevel = null): bool * Parse the table name and extract the schema and table. * * @param string $name + * * @return string[] */ public function parseSchemaAndTable(string $name): array diff --git a/src/Driver/Postgres/Query/PostgresInsertQuery.php b/src/Driver/Postgres/Query/PostgresInsertQuery.php index 2bce8532..4a0a78b2 100644 --- a/src/Driver/Postgres/Query/PostgresInsertQuery.php +++ b/src/Driver/Postgres/Query/PostgresInsertQuery.php @@ -33,6 +33,7 @@ class PostgresInsertQuery extends InsertQuery /** * @param DriverInterface $driver * @param string|null $prefix + * * @return QueryInterface */ public function withDriver(DriverInterface $driver, string $prefix = null): QueryInterface @@ -50,6 +51,7 @@ public function withDriver(DriverInterface $driver, string $prefix = null): Quer * Set returning column. If not set, the driver will detect PK automatically. * * @param string $column + * * @return $this */ public function returning(string $column): self @@ -86,10 +88,10 @@ public function run() public function getTokens(): array { return [ - 'table' => $this->table, - 'return' => $this->getPrimaryKey(), + 'table' => $this->table, + 'return' => $this->getPrimaryKey(), 'columns' => $this->columns, - 'values' => $this->values + 'values' => $this->values, ]; } diff --git a/src/Driver/Postgres/Query/PostgresSelectQuery.php b/src/Driver/Postgres/Query/PostgresSelectQuery.php index 1227fac4..c57007f4 100644 --- a/src/Driver/Postgres/Query/PostgresSelectQuery.php +++ b/src/Driver/Postgres/Query/PostgresSelectQuery.php @@ -19,8 +19,9 @@ class PostgresSelectQuery extends SelectQuery /** * Apply distinct ON to the query. * - * @param string|FragmentInterface $distinctOn - * @return self|$this + * @param FragmentInterface|string $distinctOn + * + * @return $this|self */ public function distinctOn($distinctOn): SelectQuery { diff --git a/src/Driver/Postgres/Schema/PostgresColumn.php b/src/Driver/Postgres/Schema/PostgresColumn.php index e3b3149a..39e9e75b 100644 --- a/src/Driver/Postgres/Schema/PostgresColumn.php +++ b/src/Driver/Postgres/Schema/PostgresColumn.php @@ -29,7 +29,7 @@ class PostgresColumn extends AbstractColumn 'userType', 'timezone', 'constrained', - 'constrainName' + 'constrainName', ]; /** @@ -37,77 +37,77 @@ class PostgresColumn extends AbstractColumn */ protected $mapping = [ //Primary sequences - 'primary' => ['type' => 'serial', 'autoIncrement' => true, 'nullable' => false], - 'bigPrimary' => ['type' => 'bigserial', 'autoIncrement' => true, 'nullable' => false], + 'primary' => ['type' => 'serial', 'autoIncrement' => true, 'nullable' => false], + 'bigPrimary' => ['type' => 'bigserial', 'autoIncrement' => true, 'nullable' => false], //Enum type (mapped via method) - 'enum' => 'enum', + 'enum' => 'enum', //Logical types - 'boolean' => 'boolean', + 'boolean' => 'boolean', //Integer types (size can always be changed with size method), longInteger has method alias //bigInteger - 'integer' => 'integer', + 'integer' => 'integer', 'tinyInteger' => 'smallint', - 'bigInteger' => 'bigint', + 'bigInteger' => 'bigint', //String with specified length (mapped via method) - 'string' => 'character varying', + 'string' => 'character varying', //Generic types - 'text' => 'text', - 'tinyText' => 'text', - 'longText' => 'text', + 'text' => 'text', + 'tinyText' => 'text', + 'longText' => 'text', //Real types - 'double' => 'double precision', - 'float' => 'real', + 'double' => 'double precision', + 'float' => 'real', //Decimal type (mapped via method) - 'decimal' => 'numeric', + 'decimal' => 'numeric', //Date and Time types - 'datetime' => 'timestamp without time zone', - 'date' => 'date', - 'time' => 'time without time zone', - 'timestamp' => 'timestamp without time zone', + 'datetime' => 'timestamp without time zone', + 'date' => 'date', + 'time' => 'time without time zone', + 'timestamp' => 'timestamp without time zone', 'timestamptz' => 'timestamp with time zone', //Binary types - 'binary' => 'bytea', - 'tinyBinary' => 'bytea', - 'longBinary' => 'bytea', + 'binary' => 'bytea', + 'tinyBinary' => 'bytea', + 'longBinary' => 'bytea', //Additional types - 'json' => 'text', - 'jsonb' => 'jsonb', - 'uuid' => 'uuid' + 'json' => 'text', + 'jsonb' => 'jsonb', + 'uuid' => 'uuid', ]; /** * {@inheritdoc} */ protected $reverseMapping = [ - 'primary' => ['serial'], - 'bigPrimary' => ['bigserial'], - 'enum' => ['enum'], - 'boolean' => ['boolean'], - 'integer' => ['int', 'integer', 'int4'], + 'primary' => ['serial'], + 'bigPrimary' => ['bigserial'], + 'enum' => ['enum'], + 'boolean' => ['boolean'], + 'integer' => ['int', 'integer', 'int4'], 'tinyInteger' => ['smallint'], - 'bigInteger' => ['bigint', 'int8'], - 'string' => ['character varying', 'character'], - 'text' => ['text'], - 'double' => ['double precision'], - 'float' => ['real', 'money'], - 'decimal' => ['numeric'], - 'date' => ['date'], - 'time' => ['time', 'time with time zone', 'time without time zone'], - 'timestamp' => ['timestamp', 'timestamp without time zone'], + 'bigInteger' => ['bigint', 'int8'], + 'string' => ['character varying', 'character'], + 'text' => ['text'], + 'double' => ['double precision'], + 'float' => ['real', 'money'], + 'decimal' => ['numeric'], + 'date' => ['date'], + 'time' => ['time', 'time with time zone', 'time without time zone'], + 'timestamp' => ['timestamp', 'timestamp without time zone'], 'timestamptz' => ['timestamp with time zone'], - 'binary' => ['bytea'], - 'json' => ['json'], - 'jsonb' => ['jsonb'] + 'binary' => ['bytea'], + 'json' => ['json'], + 'jsonb' => ['jsonb'], ]; /** @@ -232,6 +232,7 @@ public function sqlStatement(DriverInterface $driver): string * * @param DriverInterface $driver * @param AbstractColumn $initial + * * @return array */ public function alterOperations(DriverInterface $driver, AbstractColumn $initial): array @@ -306,6 +307,7 @@ public function alterOperations(DriverInterface $driver, AbstractColumn $initial * @param string $table Table name. * @param array $schema * @param DriverInterface $driver Postgres columns are bit more complex. + * * @return PostgresColumn */ public static function createInstance( @@ -370,15 +372,15 @@ public function compare(AbstractColumn $initial): bool return true; } - if ( + return (bool) ( in_array($this->getAbstractType(), ['primary', 'bigPrimary']) && $initial->getDefaultValue() != $this->getDefaultValue() - ) { + ) //PG adds default values to primary keys - return true; - } - return false; + + + ; } /** @@ -445,7 +447,7 @@ private function normalizeDefault(): void private static function resolveConstrains( DriverInterface $driver, array $schema, - PostgresColumn $column + self $column ): void { $query = "SELECT conname, pg_get_constraintdef(oid) as consrc FROM pg_constraint WHERE conrelid = ? AND contype = 'c' AND conkey = ?"; @@ -484,7 +486,7 @@ private static function resolveConstrains( * @param DriverInterface $driver * @param PostgresColumn $column */ - private static function resolveEnum(DriverInterface $driver, PostgresColumn $column): void + private static function resolveEnum(DriverInterface $driver, self $column): void { $range = $driver->query('SELECT enum_range(NULL::' . $column->type . ')')->fetchColumn(0); diff --git a/src/Driver/Postgres/Schema/PostgresForeignKey.php b/src/Driver/Postgres/Schema/PostgresForeignKey.php index 6ff46bab..d5c2f263 100644 --- a/src/Driver/Postgres/Schema/PostgresForeignKey.php +++ b/src/Driver/Postgres/Schema/PostgresForeignKey.php @@ -19,6 +19,7 @@ class PostgresForeignKey extends AbstractForeignKey * @param string $table * @param string $tablePrefix * @param array $schema + * * @return PostgresForeignKey */ public static function createInstance(string $table, string $tablePrefix, array $schema): self @@ -37,6 +38,7 @@ public static function createInstance(string $table, string $tablePrefix, array /** * @param array $columns + * * @return array */ private function normalizeKeys(array $columns): array diff --git a/src/Driver/Postgres/Schema/PostgresIndex.php b/src/Driver/Postgres/Schema/PostgresIndex.php index 084f8c64..cf326b39 100644 --- a/src/Driver/Postgres/Schema/PostgresIndex.php +++ b/src/Driver/Postgres/Schema/PostgresIndex.php @@ -18,6 +18,7 @@ class PostgresIndex extends AbstractIndex /** * @param string $table Table name. * @param array $schema + * * @return PostgresIndex */ public static function createInstance(string $table, array $schema): self diff --git a/src/Driver/Postgres/Schema/PostgresTable.php b/src/Driver/Postgres/Schema/PostgresTable.php index debb4128..4e78f2c3 100644 --- a/src/Driver/Postgres/Schema/PostgresTable.php +++ b/src/Driver/Postgres/Schema/PostgresTable.php @@ -301,6 +301,7 @@ protected function getNormalizedTableName(): string * Return table name without schema * * @param string $name + * * @return string */ protected function removeSchemaFromTableName(string $name): string diff --git a/src/Driver/Quoter.php b/src/Driver/Quoter.php index 40666b9d..2cee586f 100644 --- a/src/Driver/Quoter.php +++ b/src/Driver/Quoter.php @@ -59,9 +59,10 @@ public function __clone() /** * @param string $prefix * @param bool $preserveAliases + * * @return Quoter */ - public function withPrefix(string $prefix, bool $preserveAliases = false): Quoter + public function withPrefix(string $prefix, bool $preserveAliases = false): self { $quoter = clone $this; $quoter->prefix = $prefix; @@ -88,6 +89,7 @@ public function registerAlias(string $alias, string $identifier): void * Quote identifier without registering an alias. * * @param string $identifier + * * @return string */ public function identifier(string $identifier): string @@ -118,6 +120,7 @@ public function identifier(string $identifier): string * value. * @param bool $isTable Set to true to let quote method know that identifier is related to * table name. + * * @return mixed|string */ public function quote(string $identifier, bool $isTable = false): string @@ -146,6 +149,7 @@ public function quote(string $identifier, bool $isTable = false): string * Quoting columns and tables in complex expression. * * @param string $identifier + * * @return string */ private function expression(string $identifier): string @@ -172,6 +176,7 @@ function ($match) { * @param string $identifier * @param string $alias * @param bool $isTable + * * @return string */ private function aliasing(string $identifier, string $alias, bool $isTable): string @@ -205,6 +210,7 @@ private function aliasing(string $identifier, string $alias, bool $isTable): str * Processing pair of table and column. * * @param string $identifier + * * @return string */ private function paired(string $identifier): string @@ -224,6 +230,7 @@ private function paired(string $identifier): string * * @param string $identifier * @param bool $isTable + * * @return string */ private function unpaired(string $identifier, bool $isTable): string @@ -245,6 +252,7 @@ private function unpaired(string $identifier, bool $isTable): string * Check if string has expression markers. * * @param string $string + * * @return bool */ private function hasExpressions(string $string): bool diff --git a/src/Driver/SQLServer/SQLServerDriver.php b/src/Driver/SQLServer/SQLServerDriver.php index 6aac9116..085f9711 100644 --- a/src/Driver/SQLServer/SQLServerDriver.php +++ b/src/Driver/SQLServer/SQLServerDriver.php @@ -22,11 +22,11 @@ class SQLServerDriver extends Driver { - protected const DATETIME = 'Y-m-d\TH:i:s.000'; + protected const DATETIME = 'Y-m-d\TH:i:s.000'; protected const DEFAULT_PDO_OPTIONS = [ - PDO::ATTR_CASE => PDO::CASE_NATURAL, - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - PDO::ATTR_STRINGIFY_FETCHES => false + PDO::ATTR_CASE => PDO::CASE_NATURAL, + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_STRINGIFY_FETCHES => false, ]; /** @@ -61,6 +61,7 @@ public function getType(): string * * @param PDOStatement $statement * @param array $parameters + * * @return PDOStatement */ protected function bindParameters( diff --git a/src/Driver/SQLServer/SQLServerHandler.php b/src/Driver/SQLServer/SQLServerHandler.php index e72820f3..d7926513 100644 --- a/src/Driver/SQLServer/SQLServerHandler.php +++ b/src/Driver/SQLServer/SQLServerHandler.php @@ -175,7 +175,7 @@ private function renameColumn( "sp_rename ?, ?, 'COLUMN'", [ $table->getFullName() . '.' . $initial->getName(), - $column->getName() + $column->getName(), ] ); } diff --git a/src/Driver/SQLServer/Schema/SQLServerColumn.php b/src/Driver/SQLServer/Schema/SQLServerColumn.php index 08112510..31cc586b 100644 --- a/src/Driver/SQLServer/Schema/SQLServerColumn.php +++ b/src/Driver/SQLServer/Schema/SQLServerColumn.php @@ -35,7 +35,7 @@ class SQLServerColumn extends AbstractColumn 'constrainedDefault', 'defaultConstraint', 'constrainedEnum', - 'enumConstraint' + 'enumConstraint', ]; /** @@ -43,72 +43,72 @@ class SQLServerColumn extends AbstractColumn */ protected $mapping = [ //Primary sequences - 'primary' => ['type' => 'int', 'identity' => true, 'nullable' => false], - 'bigPrimary' => ['type' => 'bigint', 'identity' => true, 'nullable' => false], + 'primary' => ['type' => 'int', 'identity' => true, 'nullable' => false], + 'bigPrimary' => ['type' => 'bigint', 'identity' => true, 'nullable' => false], //Enum type (mapped via method) - 'enum' => 'enum', + 'enum' => 'enum', //Logical types - 'boolean' => 'bit', + 'boolean' => 'bit', //Integer types (size can always be changed with size method), longInteger has method alias //bigInteger - 'integer' => 'int', + 'integer' => 'int', 'tinyInteger' => 'tinyint', - 'bigInteger' => 'bigint', + 'bigInteger' => 'bigint', //String with specified length (mapped via method) - 'string' => 'varchar', + 'string' => 'varchar', //Generic types - 'text' => ['type' => 'varchar', 'size' => 0], - 'tinyText' => ['type' => 'varchar', 'size' => 0], - 'longText' => ['type' => 'varchar', 'size' => 0], + 'text' => ['type' => 'varchar', 'size' => 0], + 'tinyText' => ['type' => 'varchar', 'size' => 0], + 'longText' => ['type' => 'varchar', 'size' => 0], //Real types - 'double' => 'float', - 'float' => 'real', + 'double' => 'float', + 'float' => 'real', //Decimal type (mapped via method) - 'decimal' => 'decimal', + 'decimal' => 'decimal', //Date and Time types - 'datetime' => 'datetime', - 'date' => 'date', - 'time' => 'time', - 'timestamp' => 'datetime', + 'datetime' => 'datetime', + 'date' => 'date', + 'time' => 'time', + 'timestamp' => 'datetime', //Binary types - 'binary' => ['type' => 'varbinary', 'size' => 0], - 'tinyBinary' => ['type' => 'varbinary', 'size' => 0], - 'longBinary' => ['type' => 'varbinary', 'size' => 0], + 'binary' => ['type' => 'varbinary', 'size' => 0], + 'tinyBinary' => ['type' => 'varbinary', 'size' => 0], + 'longBinary' => ['type' => 'varbinary', 'size' => 0], //Additional types - 'json' => ['type' => 'varchar', 'size' => 0], - 'uuid' => ['type' => 'varchar', 'size' => 36], + 'json' => ['type' => 'varchar', 'size' => 0], + 'uuid' => ['type' => 'varchar', 'size' => 36], ]; /** * {@inheritdoc} */ protected $reverseMapping = [ - 'primary' => [['type' => 'int', 'identity' => true]], - 'bigPrimary' => [['type' => 'bigint', 'identity' => true]], - 'enum' => ['enum'], - 'boolean' => ['bit'], - 'integer' => ['int'], + 'primary' => [['type' => 'int', 'identity' => true]], + 'bigPrimary' => [['type' => 'bigint', 'identity' => true]], + 'enum' => ['enum'], + 'boolean' => ['bit'], + 'integer' => ['int'], 'tinyInteger' => ['tinyint', 'smallint'], - 'bigInteger' => ['bigint'], - 'text' => [['type' => 'varchar', 'size' => 0]], - 'string' => ['varchar', 'char'], - 'double' => ['float'], - 'float' => ['real'], - 'decimal' => ['decimal'], - 'timestamp' => ['datetime'], - 'date' => ['date'], - 'time' => ['time'], - 'binary' => ['varbinary'], + 'bigInteger' => ['bigint'], + 'text' => [['type' => 'varchar', 'size' => 0]], + 'string' => ['varchar', 'char'], + 'double' => ['float'], + 'float' => ['real'], + 'decimal' => ['decimal'], + 'timestamp' => ['datetime'], + 'date' => ['date'], + 'time' => ['time'], + 'binary' => ['varbinary'], ]; /** @@ -229,6 +229,7 @@ public function sqlStatement(DriverInterface $driver, bool $withEnum = true): st * * @param DriverInterface $driver * @param AbstractColumn $initial + * * @return array */ public function alterOperations(DriverInterface $driver, AbstractColumn $initial): array @@ -358,7 +359,7 @@ protected function quoteDefault(DriverInterface $driver): string { $defaultValue = parent::quoteDefault($driver); if ($this->getAbstractType() === 'boolean') { - $defaultValue = strval((int)$this->defaultValue); + $defaultValue = (string) ((int)$this->defaultValue); } return $defaultValue; @@ -396,6 +397,7 @@ protected function defaultConstrain(): string * In SQLServer we can emulate enums similar way as in Postgres via column constrain. * * @param DriverInterface $driver + * * @return string */ private function enumStatement(DriverInterface $driver): string @@ -452,7 +454,7 @@ private function normalizeDefault(): void private static function resolveEnum( DriverInterface $driver, array $schema, - SQLServerColumn $column + self $column ): void { $query = 'SELECT object_definition([o].[object_id]) AS [definition], ' . "OBJECT_NAME([o].[object_id]) AS [name]\nFROM [sys].[objects] AS [o]\n" diff --git a/src/Driver/SQLServer/Schema/SQLServerIndex.php b/src/Driver/SQLServer/Schema/SQLServerIndex.php index bb0bc5fa..539f76f2 100644 --- a/src/Driver/SQLServer/Schema/SQLServerIndex.php +++ b/src/Driver/SQLServer/Schema/SQLServerIndex.php @@ -18,6 +18,7 @@ class SQLServerIndex extends AbstractIndex /** * @param string $table Table name. * @param array $schema + * * @return SQLServerIndex */ public static function createInstance(string $table, array $schema): self @@ -28,7 +29,7 @@ public static function createInstance(string $table, array $schema): self foreach ($schema as $indexColumn) { $index->columns[] = $indexColumn['columnName']; - if (intval($indexColumn['isDescendingKey']) === 1) { + if ((int) ($indexColumn['isDescendingKey']) === 1) { $index->sort[$indexColumn['columnName']] = 'DESC'; } } diff --git a/src/Driver/SQLServer/Schema/SQlServerForeignKey.php b/src/Driver/SQLServer/Schema/SQlServerForeignKey.php index c10deec3..95000f19 100644 --- a/src/Driver/SQLServer/Schema/SQlServerForeignKey.php +++ b/src/Driver/SQLServer/Schema/SQlServerForeignKey.php @@ -19,6 +19,7 @@ class SQlServerForeignKey extends AbstractForeignKey * @param string $table * @param string $tablePrefix * @param array $schema + * * @return SQlServerForeignKey */ public static function createInstance(string $table, string $tablePrefix, array $schema): self diff --git a/src/Driver/SQLite/SQLiteHandler.php b/src/Driver/SQLite/SQLiteHandler.php index 1c3c8ce3..840272f7 100644 --- a/src/Driver/SQLite/SQLiteHandler.php +++ b/src/Driver/SQLite/SQLiteHandler.php @@ -48,6 +48,7 @@ public function getTableNames(string $prefix = ''): array /** * @param string $table + * * @return bool */ public function hasTable(string $table): bool @@ -60,6 +61,7 @@ public function hasTable(string $table): bool /** * @param string $table * @param string|null $prefix + * * @return AbstractTable */ public function getSchema(string $table, string $prefix = null): AbstractTable @@ -176,6 +178,7 @@ public function alterForeignKey( * Temporary table based on parent. * * @param AbstractTable $table + * * @return AbstractTable */ protected function createTemporary(AbstractTable $table): AbstractTable @@ -200,6 +203,7 @@ protected function createTemporary(AbstractTable $table): AbstractTable * Rebuild is required when columns or foreign keys are altered. * * @param AbstractTable $table + * * @return bool */ private function requiresRebuild(AbstractTable $table): bool @@ -255,6 +259,7 @@ private function copyData(string $source, string $to, array $mapping): void * * @param AbstractTable $source * @param AbstractTable $target + * * @return array */ private function createMapping(AbstractTable $source, AbstractTable $target): array diff --git a/src/Driver/SQLite/Schema/SQLiteColumn.php b/src/Driver/SQLite/Schema/SQLiteColumn.php index c5f56705..b4e796b7 100644 --- a/src/Driver/SQLite/Schema/SQLiteColumn.php +++ b/src/Driver/SQLite/Schema/SQLiteColumn.php @@ -35,80 +35,80 @@ class SQLiteColumn extends AbstractColumn */ protected $mapping = [ //Primary sequences - 'primary' => [ - 'type' => 'integer', + 'primary' => [ + 'type' => 'integer', 'primaryKey' => true, - 'nullable' => false, + 'nullable' => false, ], - 'bigPrimary' => [ - 'type' => 'integer', + 'bigPrimary' => [ + 'type' => 'integer', 'primaryKey' => true, - 'nullable' => false, + 'nullable' => false, ], //Enum type (mapped via method) - 'enum' => 'enum', + 'enum' => 'enum', //Logical types - 'boolean' => 'integer', + 'boolean' => 'integer', //Integer types (size can always be changed with size method), longInteger has method alias //bigInteger - 'integer' => 'integer', + 'integer' => 'integer', 'tinyInteger' => 'tinyint', - 'bigInteger' => 'bigint', + 'bigInteger' => 'bigint', //String with specified length (mapped via method) - 'string' => 'text', + 'string' => 'text', //Generic types - 'text' => 'text', - 'tinyText' => 'text', - 'longText' => 'text', + 'text' => 'text', + 'tinyText' => 'text', + 'longText' => 'text', //Real types - 'double' => 'double', - 'float' => 'real', + 'double' => 'double', + 'float' => 'real', //Decimal type (mapped via method) - 'decimal' => 'numeric', + 'decimal' => 'numeric', //Date and Time types - 'datetime' => 'datetime', - 'date' => 'date', - 'time' => 'time', - 'timestamp' => 'timestamp', + 'datetime' => 'datetime', + 'date' => 'date', + 'time' => 'time', + 'timestamp' => 'timestamp', //Binary types - 'binary' => 'blob', - 'tinyBinary' => 'blob', - 'longBinary' => 'blob', + 'binary' => 'blob', + 'tinyBinary' => 'blob', + 'longBinary' => 'blob', //Additional types - 'json' => 'text', - 'uuid' => ['type' => 'varchar', 'size' => 36], + 'json' => 'text', + 'uuid' => ['type' => 'varchar', 'size' => 36], ]; /** * {@inheritdoc} */ protected $reverseMapping = [ - 'primary' => [['type' => 'integer', 'primaryKey' => true]], - 'enum' => ['enum'], - 'boolean' => ['boolean'], - 'integer' => ['int', 'integer', 'smallint', 'mediumint'], + 'primary' => [['type' => 'integer', 'primaryKey' => true]], + 'enum' => ['enum'], + 'boolean' => ['boolean'], + 'integer' => ['int', 'integer', 'smallint', 'mediumint'], 'tinyInteger' => ['tinyint'], - 'bigInteger' => ['bigint'], - 'text' => ['text', 'string'], - 'double' => ['double'], - 'float' => ['real'], - 'decimal' => ['numeric'], - 'datetime' => ['datetime'], - 'date' => ['date'], - 'time' => ['time'], - 'timestamp' => ['timestamp'], - 'binary' => ['blob'], - 'string' => ['varchar'] + 'bigInteger' => ['bigint'], + 'text' => ['text', 'string'], + 'double' => ['double'], + 'float' => ['real'], + 'decimal' => ['numeric'], + 'datetime' => ['datetime'], + 'date' => ['date'], + 'time' => ['time'], + 'timestamp' => ['timestamp'], + 'binary' => ['blob'], + 'string' => ['varchar'], ]; /** @@ -157,6 +157,7 @@ public function sqlStatement(DriverInterface $driver): string * @param string $table * @param array $schema * @param \DateTimeZone $timezone + * * @return SQLiteColumn */ public static function createInstance( diff --git a/src/Driver/SQLite/Schema/SQLiteForeignKey.php b/src/Driver/SQLite/Schema/SQLiteForeignKey.php index 046623b2..3e1d01da 100644 --- a/src/Driver/SQLite/Schema/SQLiteForeignKey.php +++ b/src/Driver/SQLite/Schema/SQLiteForeignKey.php @@ -49,6 +49,7 @@ public function sqlStatement(DriverInterface $driver): string * Name insensitive compare. * * @param AbstractForeignKey $initial + * * @return bool */ public function compare(AbstractForeignKey $initial): bool @@ -64,6 +65,7 @@ public function compare(AbstractForeignKey $initial): bool * @param string $table * @param string $tablePrefix * @param array $schema + * * @return SQLiteForeignKey */ public static function createInstance(string $table, string $tablePrefix, array $schema): self diff --git a/src/Driver/SQLite/Schema/SQLiteIndex.php b/src/Driver/SQLite/Schema/SQLiteIndex.php index a7187e01..f4e9809a 100644 --- a/src/Driver/SQLite/Schema/SQLiteIndex.php +++ b/src/Driver/SQLite/Schema/SQLiteIndex.php @@ -21,6 +21,7 @@ class SQLiteIndex extends AbstractIndex * @param array $schema * @param array $columns * @param array $fallbackColumns + * * @return SQLiteIndex */ public static function createInstance( @@ -35,9 +36,9 @@ public static function createInstance( if ($columns !== []) { foreach ($columns as $column) { // We only need key columns - if (intval($column['cid']) > -1) { + if ((int) ($column['cid']) > -1) { $index->columns[] = $column['name']; - if (intval($column['desc']) === 1) { + if ((int) ($column['desc']) === 1) { $index->sort[$column['name']] = 'DESC'; } } diff --git a/src/Driver/SQLite/Schema/SQLiteTable.php b/src/Driver/SQLite/Schema/SQLiteTable.php index a0eb71fc..406df3df 100644 --- a/src/Driver/SQLite/Schema/SQLiteTable.php +++ b/src/Driver/SQLite/Schema/SQLiteTable.php @@ -44,8 +44,8 @@ protected function fetchColumns(): array $result[] = SQLiteColumn::createInstance( $this->getFullName(), $schema + [ - 'quoted' => $this->driver->quote($schema['name']), - 'identifier' => $this->driver->identifier($schema['name']) + 'quoted' => $this->driver->quote($schema['name']), + 'identifier' => $this->driver->identifier($schema['name']), ], $this->driver->getTimezone() ); diff --git a/src/Driver/Statement.php b/src/Driver/Statement.php index a19c1acf..2022a56f 100644 --- a/src/Driver/Statement.php +++ b/src/Driver/Statement.php @@ -73,6 +73,7 @@ public function fetchColumn(int $columnNumber = null) /** * @param int $mode + * * @return array */ public function fetchAll(int $mode = self::FETCH_ASSOC): array diff --git a/src/ForeignKeyInterface.php b/src/ForeignKeyInterface.php index df96b286..dc2a86a5 100644 --- a/src/ForeignKeyInterface.php +++ b/src/ForeignKeyInterface.php @@ -16,7 +16,7 @@ */ interface ForeignKeyInterface { - public const CASCADE = 'CASCADE'; + public const CASCADE = 'CASCADE'; public const NO_ACTION = 'NO ACTION'; /** diff --git a/src/Injection/Expression.php b/src/Injection/Expression.php index 43fc180a..36cbfdc7 100644 --- a/src/Injection/Expression.php +++ b/src/Injection/Expression.php @@ -57,9 +57,10 @@ public function __toString(): string /** * @param array $an_array + * * @return Expression */ - public static function __set_state(array $an_array): Expression + public static function __set_state(array $an_array): self { return new self( $an_array['expression'] ?? $an_array['statement'], @@ -82,7 +83,7 @@ public function getTokens(): array { return [ 'expression' => $this->expression, - 'parameters' => $this->parameters + 'parameters' => $this->parameters, ]; } } diff --git a/src/Injection/Fragment.php b/src/Injection/Fragment.php index 353052be..2e842c1f 100644 --- a/src/Injection/Fragment.php +++ b/src/Injection/Fragment.php @@ -53,9 +53,10 @@ public function __toString(): string /** * @param array $an_array + * * @return Fragment */ - public static function __set_state(array $an_array): Fragment + public static function __set_state(array $an_array): self { return new self( $an_array['fragment'] ?? $an_array['statement'], @@ -77,8 +78,8 @@ public function getType(): int public function getTokens(): array { return [ - 'fragment' => $this->fragment, - 'parameters' => $this->parameters + 'fragment' => $this->fragment, + 'parameters' => $this->parameters, ]; } } diff --git a/src/Injection/Parameter.php b/src/Injection/Parameter.php index b9bd8483..129a9ca8 100644 --- a/src/Injection/Parameter.php +++ b/src/Injection/Parameter.php @@ -24,7 +24,7 @@ class Parameter implements ParameterInterface */ public const DETECT_TYPE = 900888; - /** @var mixed|array */ + /** @var array|mixed */ private $value; /** @var int */ @@ -46,7 +46,7 @@ public function __debugInfo() { return [ 'value' => $this->value, - 'type' => $this->type + 'type' => $this->type, ]; } diff --git a/src/Injection/ParameterInterface.php b/src/Injection/ParameterInterface.php index c74389b9..e814d952 100644 --- a/src/Injection/ParameterInterface.php +++ b/src/Injection/ParameterInterface.php @@ -25,7 +25,7 @@ interface ParameterInterface /** * Get mocked parameter value or values in array form. * - * @return mixed|array + * @return array|mixed */ public function getValue(); diff --git a/src/Query/ActiveQuery.php b/src/Query/ActiveQuery.php index f4f25210..34dfa178 100644 --- a/src/Query/ActiveQuery.php +++ b/src/Query/ActiveQuery.php @@ -56,15 +56,16 @@ public function __debugInfo() return [ 'queryString' => Interpolator::interpolate($queryString, $parameters->getParameters()), - 'parameters' => $parameters->getParameters(), - 'driver' => $this->driver + 'parameters' => $parameters->getParameters(), + 'driver' => $this->driver, ]; } /** * @param DriverInterface $driver * @param string|null $prefix - * @return QueryInterface|$this + * + * @return $this|QueryInterface */ public function withDriver(DriverInterface $driver, string $prefix = null): QueryInterface { @@ -95,6 +96,7 @@ public function getPrefix(): ?string * Generate SQL query, must have associated driver instance. * * @param QueryParameters|null $parameters + * * @return string */ public function sqlStatement(QueryParameters $parameters = null): string @@ -113,10 +115,10 @@ public function sqlStatement(QueryParameters $parameters = null): string /** * Compile and run query. * - * @return mixed - * * @throws BuilderException * @throws StatementException + * + * @return mixed */ abstract public function run(); diff --git a/src/Query/BuilderInterface.php b/src/Query/BuilderInterface.php index 113fb146..e8066273 100644 --- a/src/Query/BuilderInterface.php +++ b/src/Query/BuilderInterface.php @@ -20,7 +20,8 @@ interface BuilderInterface { /** * @param DriverInterface $driver - * @return BuilderInterface|$this + * + * @return $this|BuilderInterface */ public function withDriver(DriverInterface $driver): self; @@ -29,6 +30,7 @@ public function withDriver(DriverInterface $driver): self; * * @param string $prefix * @param string|null $table + * * @return InsertQuery */ public function insertQuery( @@ -42,6 +44,7 @@ public function insertQuery( * @param string $prefix * @param array $from * @param array $columns + * * @return SelectQuery */ public function selectQuery( @@ -54,6 +57,7 @@ public function selectQuery( * @param string $prefix * @param string|null $from * @param array $where + * * @return DeleteQuery */ public function deleteQuery( @@ -69,6 +73,7 @@ public function deleteQuery( * @param string|null $table * @param array $where * @param array $values + * * @return UpdateQuery */ public function updateQuery( diff --git a/src/Query/DeleteQuery.php b/src/Query/DeleteQuery.php index 7fd029aa..d05273d2 100644 --- a/src/Query/DeleteQuery.php +++ b/src/Query/DeleteQuery.php @@ -43,9 +43,10 @@ public function __construct(string $table = null, array $where = []) * Change target table. * * @param string $into Table name without prefix. + * * @return self */ - public function from(string $into): DeleteQuery + public function from(string $into): self { $this->table = $into; @@ -80,7 +81,7 @@ public function getTokens(): array { return [ 'table' => $this->table, - 'where' => $this->whereTokens + 'where' => $this->whereTokens, ]; } } diff --git a/src/Query/InsertQuery.php b/src/Query/InsertQuery.php index f505dc61..822e7d3e 100644 --- a/src/Query/InsertQuery.php +++ b/src/Query/InsertQuery.php @@ -12,7 +12,6 @@ namespace Cycle\Database\Query; use Cycle\Database\Driver\CompilerInterface; -use Cycle\Database\Exception\BuilderException; use Cycle\Database\Injection\Parameter; /** @@ -41,9 +40,10 @@ public function __construct(string $table = null) * Set target insertion table. * * @param string $into + * * @return self */ - public function into(string $into): InsertQuery + public function into(string $into): self { $this->table = $into; @@ -60,9 +60,10 @@ public function into(string $into): InsertQuery * $insert->columns("name, email"); * * @param array|string $columns + * * @return self */ - public function columns(...$columns): InsertQuery + public function columns(...$columns): self { $this->columns = $this->fetchIdentifiers($columns); @@ -92,9 +93,10 @@ public function columns(...$columns): InsertQuery * ]); * * @param mixed $rowsets + * * @return self */ - public function values($rowsets): InsertQuery + public function values($rowsets): self { if (!is_array($rowsets)) { return $this->values(func_get_args()); @@ -159,9 +161,9 @@ public function getType(): int public function getTokens(): array { return [ - 'table' => $this->table, + 'table' => $this->table, 'columns' => $this->columns, - 'values' => $this->values + 'values' => $this->values, ]; } } diff --git a/src/Query/Interpolator.php b/src/Query/Interpolator.php index c6e5ebe1..f78b98b4 100644 --- a/src/Query/Interpolator.php +++ b/src/Query/Interpolator.php @@ -25,6 +25,7 @@ final class Interpolator * * @param string $query * @param iterable $parameters + * * @return string */ public static function interpolate(string $query, iterable $parameters = []): string @@ -58,6 +59,7 @@ public static function interpolate(string $query, iterable $parameters = []): st * Get parameter value. * * @param mixed $parameter + * * @return string */ protected static function resolveValue($parameter): string @@ -103,6 +105,7 @@ protected static function resolveValue($parameter): string * @param string $search * @param string $replace * @param string $subject + * * @return string */ private static function replaceOnce( diff --git a/src/Query/QueryBuilder.php b/src/Query/QueryBuilder.php index 8333b089..baab2b78 100644 --- a/src/Query/QueryBuilder.php +++ b/src/Query/QueryBuilder.php @@ -55,6 +55,7 @@ public function __construct( /** * @param DriverInterface $driver + * * @return BuilderInterface */ public function withDriver(DriverInterface $driver): BuilderInterface @@ -70,6 +71,7 @@ public function withDriver(DriverInterface $driver): BuilderInterface * * @param string $prefix * @param string|null $table + * * @return InsertQuery */ public function insertQuery( @@ -91,6 +93,7 @@ public function insertQuery( * @param string $prefix * @param array $from * @param array $columns + * * @return SelectQuery */ public function selectQuery( @@ -111,6 +114,7 @@ public function selectQuery( * @param string $prefix * @param string|null $from * @param array $where + * * @return DeleteQuery */ public function deleteQuery( @@ -134,6 +138,7 @@ public function deleteQuery( * @param string|null $table * @param array $where * @param array $values + * * @return UpdateQuery */ public function updateQuery( @@ -154,7 +159,7 @@ public function updateQuery( /** * @return QueryBuilder */ - public static function defaultBuilder(): QueryBuilder + public static function defaultBuilder(): self { return new self( new SelectQuery(), diff --git a/src/Query/QueryInterface.php b/src/Query/QueryInterface.php index 41c55f4e..b1c29355 100644 --- a/src/Query/QueryInterface.php +++ b/src/Query/QueryInterface.php @@ -21,6 +21,7 @@ interface QueryInterface extends FragmentInterface * * @param DriverInterface $driver * @param string|null $prefix + * * @return $this */ public function withDriver(DriverInterface $driver, string $prefix = null): self; diff --git a/src/Query/SelectQuery.php b/src/Query/SelectQuery.php index 8fb5f400..678c6170 100644 --- a/src/Query/SelectQuery.php +++ b/src/Query/SelectQuery.php @@ -31,13 +31,13 @@ class SelectQuery extends ActiveQuery implements IteratorAggregate, PaginableInterface { - use TokenTrait; - use WhereTrait; use HavingTrait; use JoinTrait; + use TokenTrait; + use WhereTrait; // sort directions - public const SORT_ASC = 'ASC'; + public const SORT_ASC = 'ASC'; public const SORT_DESC = 'DESC'; /** @var array */ @@ -52,7 +52,7 @@ class SelectQuery extends ActiveQuery implements /** @var array */ protected $columns = ['*']; - /** @var string[][]|FragmentInterface[][] */ + /** @var FragmentInterface[][]|string[][] */ protected $orderBy = []; /** @var array */ @@ -82,11 +82,12 @@ public function __construct(array $from = [], array $columns = []) /** * Mark query to return only distinct results. * - * @param bool|string|FragmentInterface $distinct You are only allowed to use string value for + * @param bool|FragmentInterface|string $distinct You are only allowed to use string value for * Postgres databases. - * @return self|$this + * + * @return $this|self */ - public function distinct($distinct = true): SelectQuery + public function distinct($distinct = true): self { $this->distinct = $distinct; @@ -97,10 +98,11 @@ public function distinct($distinct = true): SelectQuery * Set table names SELECT query should be performed for. Table names can be provided with * specified alias (AS construction). * - * @param array|string|mixed $tables - * @return self|$this + * @param array|mixed|string $tables + * + * @return $this|self */ - public function from($tables): SelectQuery + public function from($tables): self { $this->tables = $this->fetchIdentifiers(func_get_args()); @@ -119,10 +121,11 @@ public function getTables(): array * Set columns should be fetched as result of SELECT query. Columns can be provided with * specified alias (AS construction). * - * @param array|string|mixed $columns - * @return self|$this + * @param array|mixed|string $columns + * + * @return $this|self */ - public function columns($columns): SelectQuery + public function columns($columns): self { $this->columns = $this->fetchIdentifiers(func_get_args()); @@ -140,9 +143,9 @@ public function getColumns(): array /** * Select entities for the following update. * - * @return self|$this + * @return $this|self */ - public function forUpdate(): SelectQuery + public function forUpdate(): self { $this->forUpdate = true; @@ -158,11 +161,12 @@ public function forUpdate(): SelectQuery * 'name' => SelectQuery::SORT_ASC * ]); * - * @param string|array $expression + * @param array|string $expression * @param string $direction Sorting direction, ASC|DESC. - * @return self|$this + * + * @return $this|self */ - public function orderBy($expression, $direction = self::SORT_ASC): SelectQuery + public function orderBy($expression, $direction = self::SORT_ASC): self { if (!is_array($expression)) { $this->addOrder($expression, $direction); @@ -180,9 +184,10 @@ public function orderBy($expression, $direction = self::SORT_ASC): SelectQuery * Column or expression to group query by. * * @param string $expression - * @return self|$this + * + * @return $this|self */ - public function groupBy($expression): SelectQuery + public function groupBy($expression): self { $this->groupBy[] = $expression; @@ -193,9 +198,10 @@ public function groupBy($expression): SelectQuery * Add select query to be united with. * * @param FragmentInterface $query - * @return self|$this + * + * @return $this|self */ - public function union(FragmentInterface $query): SelectQuery + public function union(FragmentInterface $query): self { $this->unionTokens[] = ['', $query]; @@ -207,9 +213,9 @@ public function union(FragmentInterface $query): SelectQuery * * @param FragmentInterface $query * - * @return self|$this + * @return $this|self */ - public function unionAll(FragmentInterface $query): SelectQuery + public function unionAll(FragmentInterface $query): self { $this->unionTokens[] = ['ALL', $query]; @@ -221,9 +227,10 @@ public function unionAll(FragmentInterface $query): SelectQuery * only changes pagination window. Set to 0 to disable limiting. * * @param int|null $limit - * @return self|$this + * + * @return $this|self */ - public function limit(int $limit = null): SelectQuery + public function limit(int $limit = null): self { $this->limit = $limit; @@ -243,9 +250,10 @@ public function getLimit(): ?int * changes pagination window. * * @param int|null $offset - * @return self|$this + * + * @return $this|self */ - public function offset(int $offset = null): SelectQuery + public function offset(int $offset = null): self { $this->offset = $offset; @@ -317,6 +325,7 @@ public function runChunks(int $limit, callable $callback): void * Count number of rows in query. Limit, offset, order by, group by values will be ignored. * * @param string $column Column to count by (every column by default). + * * @return int */ public function count(string $column = '*'): int @@ -338,6 +347,7 @@ public function count(string $column = '*'): int /** * @param string $column + * * @return mixed */ public function avg(string $column) @@ -347,6 +357,7 @@ public function avg(string $column) /** * @param string $column + * * @return mixed */ public function max(string $column) @@ -356,6 +367,7 @@ public function max(string $column) /** * @param string $column + * * @return mixed */ public function min(string $column) @@ -365,6 +377,7 @@ public function min(string $column) /** * @param string $column + * * @return mixed */ public function sum(string $column) @@ -412,26 +425,27 @@ public function getTokens(): array { return [ 'forUpdate' => $this->forUpdate, - 'from' => $this->tables, - 'join' => $this->joinTokens, - 'columns' => $this->columns, - 'distinct' => $this->distinct, - 'where' => $this->whereTokens, - 'having' => $this->havingTokens, - 'groupBy' => $this->groupBy, - 'orderBy' => array_values($this->orderBy), - 'limit' => $this->limit, - 'offset' => $this->offset, - 'union' => $this->unionTokens, + 'from' => $this->tables, + 'join' => $this->joinTokens, + 'columns' => $this->columns, + 'distinct' => $this->distinct, + 'where' => $this->whereTokens, + 'having' => $this->havingTokens, + 'groupBy' => $this->groupBy, + 'orderBy' => array_values($this->orderBy), + 'limit' => $this->limit, + 'offset' => $this->offset, + 'union' => $this->unionTokens, ]; } /** - * @param string|FragmentInterface $field + * @param FragmentInterface|string $field * @param string $order Sorting direction, ASC|DESC. - * @return self|$this + * + * @return $this|self */ - private function addOrder($field, string $order): SelectQuery + private function addOrder($field, string $order): self { if (!is_string($field)) { $this->orderBy[] = [$field, $order]; @@ -444,6 +458,7 @@ private function addOrder($field, string $order): SelectQuery /** * @param string $method * @param string $column + * * @return mixed */ private function runAggregate(string $method, string $column) diff --git a/src/Query/Traits/HavingTrait.php b/src/Query/Traits/HavingTrait.php index fea63800..41523923 100644 --- a/src/Query/Traits/HavingTrait.php +++ b/src/Query/Traits/HavingTrait.php @@ -26,9 +26,10 @@ trait HavingTrait * Simple HAVING condition with various set of arguments. * * @param mixed ...$args [(column, value), (column, operator, value)] - * @return self|$this * * @throws BuilderException + * + * @return $this|self */ public function having(...$args): self { @@ -46,9 +47,10 @@ public function having(...$args): self * Simple AND HAVING condition with various set of arguments. * * @param mixed ...$args [(column, value), (column, operator, value)] - * @return self|$this * * @throws BuilderException + * + * @return $this|self */ public function andHaving(...$args): self { @@ -67,9 +69,9 @@ public function andHaving(...$args): self * * @param mixed ...$args [(column, value), (column, operator, value)] * - * @return self|$this - * * @throws BuilderException + * + * @return $this|self */ public function orHaving(...$args): self { diff --git a/src/Query/Traits/JoinTrait.php b/src/Query/Traits/JoinTrait.php index c8bb712a..b97f9ccf 100644 --- a/src/Query/Traits/JoinTrait.php +++ b/src/Query/Traits/JoinTrait.php @@ -54,7 +54,6 @@ */ trait JoinTrait { - /** * Set of join tokens with on and on where conditions associated, must be supported by * QueryCompilers. @@ -73,22 +72,23 @@ trait JoinTrait * Register new JOIN with specified type with set of on conditions (linking one table to * another, no parametric on conditions allowed here). * - * @param string|ActiveQuery $type Join type. Allowed values, LEFT, RIGHT, INNER and etc. + * @param ActiveQuery|string $type Join type. Allowed values, LEFT, RIGHT, INNER and etc. * @param string $outer Joined table name (without prefix), may include AS statement. * @param string $alias Joined table or query alias. * @param mixed $on Simplified on definition linking table names (no * parameters allowed) or closure. - * @return $this * * @throws BuilderException + * + * @return $this */ public function join($type, $outer, string $alias = null, $on = null): self { $this->joinTokens[++$this->lastJoin] = [ 'outer' => $outer, 'alias' => $alias, - 'type' => strtoupper($type), - 'on' => [] + 'type' => strtoupper($type), + 'on' => [], ]; return call_user_func_array([$this, 'on'], array_slice(func_get_args(), 2)); @@ -101,19 +101,20 @@ public function join($type, $outer, string $alias = null, $on = null): self * @link http://www.w3schools.com/sql/sql_join_inner.asp * @see join() * - * @param string|ActiveQuery $outer Joined table name (without prefix), may include AS statement. + * @param ActiveQuery|string $outer Joined table name (without prefix), may include AS statement. * @param string $alias Joined table or query alias. - * @return $this * * @throws BuilderException + * + * @return $this */ public function innerJoin($outer, string $alias = null): self { $this->joinTokens[++$this->lastJoin] = [ 'outer' => $outer, 'alias' => $alias, - 'type' => 'INNER', - 'on' => [] + 'type' => 'INNER', + 'on' => [], ]; return $this; @@ -126,21 +127,22 @@ public function innerJoin($outer, string $alias = null): self * @link http://www.w3schools.com/sql/sql_join_right.asp * @see join() * - * @param string|ActiveQuery $outer Joined table name (without prefix), may include AS statement. + * @param ActiveQuery|string $outer Joined table name (without prefix), may include AS statement. * @param string $alias Joined table or query alias. * @param mixed $on Simplified on definition linking table names (no * parameters allowed) or closure. - * @return $this * * @throws BuilderException + * + * @return $this */ public function rightJoin($outer, string $alias = null, $on = null): self { $this->joinTokens[++$this->lastJoin] = [ 'outer' => $outer, 'alias' => $alias, - 'type' => 'RIGHT', - 'on' => [] + 'type' => 'RIGHT', + 'on' => [], ]; return $this; @@ -154,19 +156,20 @@ public function rightJoin($outer, string $alias = null, $on = null): self * @link http://www.w3schools.com/sql/sql_join_left.asp * @see join() * - * @param string|ActiveQuery $outer Joined table name (without prefix), may include AS statement. + * @param ActiveQuery|string $outer Joined table name (without prefix), may include AS statement. * @param string $alias Joined table or query alias. - * @return $this * * @throws BuilderException + * + * @return $this */ public function leftJoin($outer, string $alias = null): self { $this->joinTokens[++$this->lastJoin] = [ 'outer' => $outer, 'alias' => $alias, - 'type' => 'LEFT', - 'on' => [] + 'type' => 'LEFT', + 'on' => [], ]; return $this; @@ -180,19 +183,20 @@ public function leftJoin($outer, string $alias = null): self * @link http://www.w3schools.com/sql/sql_join_full.asp * @see join() * - * @param string|ActiveQuery $outer Joined table name (without prefix), may include AS statement. + * @param ActiveQuery|string $outer Joined table name (without prefix), may include AS statement. * @param string $alias Joined table or query alias. - * @return $this * * @throws BuilderException + * + * @return $this */ public function fullJoin($outer, string $alias = null): self { $this->joinTokens[++$this->lastJoin] = [ 'outer' => $outer, 'alias' => $alias, - 'type' => 'FULL', - 'on' => [] + 'type' => 'FULL', + 'on' => [], ]; return $this; @@ -203,9 +207,10 @@ public function fullJoin($outer, string $alias = null): self * together, no parametric values allowed. * * @param mixed ...$args [(column, outer column), (column, operator, outer column)] - * @return $this * * @throws BuilderException + * + * @return $this */ public function on(...$args): self { @@ -224,9 +229,10 @@ public function on(...$args): self * together, no parametric values allowed. * * @param mixed ...$args [(column, outer column), (column, operator, outer column)] - * @return $this * * @throws BuilderException + * + * @return $this */ public function andOn(...$args): self { @@ -245,9 +251,10 @@ public function andOn(...$args): self * together, no parametric values allowed. * * @param mixed ...$args [(column, outer column), (column, operator, outer column)] - * @return $this * * @throws BuilderException + * + * @return $this */ public function orOn(...$args): self { @@ -266,11 +273,12 @@ public function orOn(...$args): self * such methods. * * @param mixed ...$args [(column, value), (column, operator, value)] - * @return $this * * @throws BuilderException - * @see AbstractWhere * + * @return $this + * + * @see AbstractWhere */ public function onWhere(...$args): self { @@ -289,11 +297,12 @@ public function onWhere(...$args): self * such methods. * * @param mixed ...$args [(column, value), (column, operator, value)] - * @return $this * * @throws BuilderException - * @see AbstractWhere * + * @return $this + * + * @see AbstractWhere */ public function andOnWhere(...$args): self { @@ -312,11 +321,12 @@ public function andOnWhere(...$args): self * such methods. * * @param mixed ...$args [(column, value), (column, operator, value)] - * @return $this * * @throws BuilderException - * @see AbstractWhere * + * @return $this + * + * @see AbstractWhere */ public function orOnWhere(...$args): self { diff --git a/src/Query/Traits/TokenTrait.php b/src/Query/Traits/TokenTrait.php index 991614af..a6446412 100644 --- a/src/Query/Traits/TokenTrait.php +++ b/src/Query/Traits/TokenTrait.php @@ -94,7 +94,7 @@ protected function registerToken($boolean, array $params, &$tokens, callable $wr // AND|OR [name] = [valueA] $tokens[] = [ $boolean, - [$params[0], '=', $wrapper($params[1])] + [$params[0], '=', $wrapper($params[1])], ]; break; case 3: @@ -112,7 +112,7 @@ protected function registerToken($boolean, array $params, &$tokens, callable $wr // AND|OR [name] [valueA: OPERATION] [valueA] $tokens[] = [ $boolean, - [$name, $operator, $wrapper($value)] + [$name, $operator, $wrapper($value)], ]; break; case 4: @@ -135,8 +135,8 @@ protected function registerToken($boolean, array $params, &$tokens, callable $wr $name, strtoupper($operator), $wrapper($params[2]), - $wrapper($params[3]) - ] + $wrapper($params[3]), + ], ]; break; default: @@ -186,7 +186,7 @@ private function flattenWhere(string $grouper, array $where, &$tokens, callable if (!is_array($value)) { $tokens[] = [ $boolean, - [$key, '=', $wrapper($value)] + [$key, '=', $wrapper($value)], ]; continue; } @@ -217,6 +217,7 @@ private function flattenWhere(string $grouper, array $where, &$tokens, callable * @param array $where Operations associated with identifier. * @param array $tokens Array to aggregate compiled tokens. Reference. * @param callable $wrapper Callback or closure used to wrap/collect every potential parameter. + * * @return array */ private function pushCondition(string $innerJoiner, string $key, $where, &$tokens, callable $wrapper): array @@ -231,7 +232,7 @@ private function pushCondition(string $innerJoiner, string $key, $where, &$token // AND|OR [name] [OPERATION] [nestedValue] $tokens[] = [ $innerJoiner, - [$key, $operation, $wrapper($value)] + [$key, $operation, $wrapper($value)], ]; continue; } diff --git a/src/Query/Traits/WhereTrait.php b/src/Query/Traits/WhereTrait.php index 1745af8f..0b1d41b2 100644 --- a/src/Query/Traits/WhereTrait.php +++ b/src/Query/Traits/WhereTrait.php @@ -26,9 +26,10 @@ trait WhereTrait * Simple WHERE condition with various set of arguments. * * @param mixed ...$args [(column, value), (column, operator, value)] - * @return self|$this * * @throws BuilderException + * + * @return $this|self */ public function where(...$args): self { @@ -46,9 +47,10 @@ public function where(...$args): self * Simple AND WHERE condition with various set of arguments. * * @param mixed ...$args [(column, value), (column, operator, value)] - * @return self|$this * * @throws BuilderException + * + * @return $this|self */ public function andWhere(...$args): self { @@ -66,9 +68,10 @@ public function andWhere(...$args): self * Simple OR WHERE condition with various set of arguments. * * @param mixed ...$args [(column, value), (column, operator, value)] - * @return self|$this * * @throws BuilderException + * + * @return $this|self */ public function orWhere(...$args): self { @@ -90,6 +93,7 @@ public function orWhere(...$args): self * @param array $tokens Array to aggregate compiled tokens. Reference. * @param callable $wrapper Callback or closure used to wrap/collect every potential * parameter. + * * @throws BuilderException */ abstract protected function registerToken( diff --git a/src/Query/UpdateQuery.php b/src/Query/UpdateQuery.php index 4be0b1fd..b6150b57 100644 --- a/src/Query/UpdateQuery.php +++ b/src/Query/UpdateQuery.php @@ -51,9 +51,10 @@ public function __construct( * Change target table. * * @param string $table Table name without prefix. - * @return self|$this + * + * @return $this|self */ - public function in(string $table): UpdateQuery + public function in(string $table): self { $this->table = $table; @@ -65,9 +66,10 @@ public function in(string $table): UpdateQuery * value to be set. * * @param array $values - * @return self|$this + * + * @return $this|self */ - public function values(array $values): UpdateQuery + public function values(array $values): self { $this->values = $values; @@ -79,9 +81,10 @@ public function values(array $values): UpdateQuery * * @param string $column * @param mixed $value - * @return self|$this + * + * @return $this|self */ - public function set(string $column, $value): UpdateQuery + public function set(string $column, $value): self { $this->values[$column] = $value; @@ -117,9 +120,9 @@ public function getType(): int public function getTokens(): array { return [ - 'table' => $this->table, + 'table' => $this->table, 'values' => $this->values, - 'where' => $this->whereTokens + 'where' => $this->whereTokens, ]; } } diff --git a/src/Schema/AbstractColumn.php b/src/Schema/AbstractColumn.php index 315596ef..bb0beb8f 100644 --- a/src/Schema/AbstractColumn.php +++ b/src/Schema/AbstractColumn.php @@ -27,26 +27,26 @@ * * Shortcuts for various column types: * - * @method AbstractColumn|$this primary() - * @method AbstractColumn|$this bigPrimary() - * @method AbstractColumn|$this boolean() - * @method AbstractColumn|$this integer() - * @method AbstractColumn|$this tinyInteger() - * @method AbstractColumn|$this bigInteger() - * @method AbstractColumn|$this text() - * @method AbstractColumn|$this tinyText() - * @method AbstractColumn|$this longText() - * @method AbstractColumn|$this double() - * @method AbstractColumn|$this float() - * @method AbstractColumn|$this datetime() - * @method AbstractColumn|$this date() - * @method AbstractColumn|$this time() - * @method AbstractColumn|$this timestamp() - * @method AbstractColumn|$this binary() - * @method AbstractColumn|$this tinyBinary() - * @method AbstractColumn|$this longBinary() - * @method AbstractColumn|$this json() - * @method AbstractColumn|$this uuid() + * @method $this|AbstractColumn primary() + * @method $this|AbstractColumn bigPrimary() + * @method $this|AbstractColumn boolean() + * @method $this|AbstractColumn integer() + * @method $this|AbstractColumn tinyInteger() + * @method $this|AbstractColumn bigInteger() + * @method $this|AbstractColumn text() + * @method $this|AbstractColumn tinyText() + * @method $this|AbstractColumn longText() + * @method $this|AbstractColumn double() + * @method $this|AbstractColumn float() + * @method $this|AbstractColumn datetime() + * @method $this|AbstractColumn date() + * @method $this|AbstractColumn time() + * @method $this|AbstractColumn timestamp() + * @method $this|AbstractColumn binary() + * @method $this|AbstractColumn tinyBinary() + * @method $this|AbstractColumn longBinary() + * @method $this|AbstractColumn json() + * @method $this|AbstractColumn uuid() */ abstract class AbstractColumn implements ColumnInterface, ElementInterface { @@ -84,49 +84,49 @@ abstract class AbstractColumn implements ColumnInterface, ElementInterface */ protected $mapping = [ //Primary sequences - 'primary' => null, - 'bigPrimary' => null, + 'primary' => null, + 'bigPrimary' => null, //Enum type (mapped via method) - 'enum' => null, + 'enum' => null, //Logical types - 'boolean' => null, + 'boolean' => null, //Integer types (size can always be changed with size method), longInteger has method alias //bigInteger - 'integer' => null, + 'integer' => null, 'tinyInteger' => null, - 'bigInteger' => null, + 'bigInteger' => null, //String with specified length (mapped via method) - 'string' => null, + 'string' => null, //Generic types - 'text' => null, - 'tinyText' => null, - 'longText' => null, + 'text' => null, + 'tinyText' => null, + 'longText' => null, //Real types - 'double' => null, - 'float' => null, + 'double' => null, + 'float' => null, //Decimal type (mapped via method) - 'decimal' => null, + 'decimal' => null, //Date and Time types - 'datetime' => null, - 'date' => null, - 'time' => null, - 'timestamp' => null, + 'datetime' => null, + 'date' => null, + 'time' => null, + 'timestamp' => null, //Binary types - 'binary' => null, - 'tinyBinary' => null, - 'longBinary' => null, + 'binary' => null, + 'tinyBinary' => null, + 'longBinary' => null, //Additional types - 'json' => null, + 'json' => null, ]; /** @@ -138,28 +138,28 @@ abstract class AbstractColumn implements ColumnInterface, ElementInterface * @var array */ protected $reverseMapping = [ - 'primary' => [], - 'bigPrimary' => [], - 'enum' => [], - 'boolean' => [], - 'integer' => [], + 'primary' => [], + 'bigPrimary' => [], + 'enum' => [], + 'boolean' => [], + 'integer' => [], 'tinyInteger' => [], - 'bigInteger' => [], - 'string' => [], - 'text' => [], - 'tinyText' => [], - 'longText' => [], - 'double' => [], - 'float' => [], - 'decimal' => [], - 'datetime' => [], - 'date' => [], - 'time' => [], - 'timestamp' => [], - 'binary' => [], - 'tinyBinary' => [], - 'longBinary' => [], - 'json' => [], + 'bigInteger' => [], + 'string' => [], + 'text' => [], + 'tinyText' => [], + 'longText' => [], + 'double' => [], + 'float' => [], + 'decimal' => [], + 'datetime' => [], + 'date' => [], + 'time' => [], + 'timestamp' => [], + 'binary' => [], + 'tinyBinary' => [], + 'longBinary' => [], + 'json' => [], ]; /** @@ -230,12 +230,12 @@ abstract class AbstractColumn implements ColumnInterface, ElementInterface * @var array */ private $aliases = [ - 'int' => 'integer', - 'bigint' => 'bigInteger', - 'incremental' => 'primary', + 'int' => 'integer', + 'bigint' => 'bigInteger', + 'incremental' => 'primary', 'bigIncremental' => 'bigPrimary', - 'bool' => 'boolean', - 'blob' => 'binary', + 'bool' => 'boolean', + 'blob' => 'binary', ]; /** @@ -247,8 +247,8 @@ abstract class AbstractColumn implements ColumnInterface, ElementInterface * @var array */ private $phpMapping = [ - self::INT => ['primary', 'bigPrimary', 'integer', 'tinyInteger', 'bigInteger'], - self::BOOL => ['boolean'], + self::INT => ['primary', 'bigPrimary', 'integer', 'tinyInteger', 'bigInteger'], + self::BOOL => ['boolean'], self::FLOAT => ['double', 'float', 'decimal'], ]; @@ -269,9 +269,10 @@ public function __construct(string $table, string $name, \DateTimeZone $timezone * * @param string $type Abstract type. * @param array $arguments Not used. + * * @return self */ - public function __call(string $type, array $arguments = []): AbstractColumn + public function __call(string $type, array $arguments = []): self { return $this->type($type); } @@ -295,8 +296,8 @@ public function __debugInfo() 'name' => $this->name, 'type' => [ 'database' => $this->type, - 'schema' => $this->getAbstractType(), - 'php' => $this->getType(), + 'schema' => $this->getAbstractType(), + 'php' => $this->getType(), ], ]; @@ -448,6 +449,7 @@ public function getType(): string * declaration process. Value will become null after the schema fetched from database. * * @return string|null + * * @internal */ public function getDeclaredType(): ?string @@ -502,12 +504,14 @@ public function getAbstractType(): string * cross type conversions and etc. Try do not change column type without a reason. * * @param string $abstract Abstract or virtual type declared in mapping. - * @return self|$this * * @throws SchemaException + * + * @return $this|self + * * @todo Support native database types (simply bypass abstractType)! */ - public function type(string $abstract): AbstractColumn + public function type(string $abstract): self { if (isset($this->aliases[$abstract])) { //Make recursive @@ -544,9 +548,10 @@ public function type(string $abstract): AbstractColumn * Set column nullable/not nullable. * * @param bool $nullable - * @return self|$this + * + * @return $this|self */ - public function nullable(bool $nullable = true): AbstractColumn + public function nullable(bool $nullable = true): self { $this->nullable = $nullable; @@ -558,9 +563,10 @@ public function nullable(bool $nullable = true): AbstractColumn * Use Database::TIMESTAMP_NOW to use driver specific NOW() function. * * @param mixed $value - * @return self|$this + * + * @return $this|self */ - public function defaultValue($value): AbstractColumn + public function defaultValue($value): self { //Forcing driver specific values if ($value === self::DATETIME_NOW) { @@ -580,10 +586,11 @@ public function defaultValue($value): AbstractColumn * $table->status->enum(['active', 'disabled']); * $table->status->enum('active', 'disabled'); * - * @param string|array $values Enum values (array or comma separated). String values only. + * @param array|string $values Enum values (array or comma separated). String values only. + * * @return self */ - public function enum($values): AbstractColumn + public function enum($values): self { $this->type('enum'); $this->enumValues = array_map( @@ -605,11 +612,12 @@ public function enum($values): AbstractColumn * @link http://stackoverflow.com/questions/386294/what-is-the-maximum-length-of-a-valid-email-address * * @param int $size Max string length. - * @return self|$this * * @throws SchemaException + * + * @return $this|self */ - public function string(int $size = 255): AbstractColumn + public function string(int $size = 255): self { $this->type('string'); @@ -629,11 +637,12 @@ public function string(int $size = 255): AbstractColumn * * @param int $precision * @param int $scale - * @return self|$this * * @throws SchemaException + * + * @return $this|self */ - public function decimal(int $precision, int $scale = 0): AbstractColumn + public function decimal(int $precision, int $scale = 0): self { $this->type('decimal'); @@ -676,9 +685,10 @@ public function sqlStatement(DriverInterface $driver): string /** * @param AbstractColumn $initial + * * @return bool */ - public function compare(AbstractColumn $initial): bool + public function compare(self $initial): bool { $normalized = clone $initial; @@ -722,6 +732,7 @@ public function compare(AbstractColumn $initial): bool * Get database specific enum type definition options. * * @param DriverInterface $driver + * * @return string */ protected function quoteEnum(DriverInterface $driver): string @@ -742,6 +753,7 @@ protected function quoteEnum(DriverInterface $driver): string * Must return driver specific default value. * * @param DriverInterface $driver + * * @return string */ protected function quoteDefault(DriverInterface $driver): string @@ -779,9 +791,10 @@ protected function quoteDefault(DriverInterface $driver): string * * @param string $type * @param string $value - * @return string|FragmentInterface|\DateTime * * @throws DefaultValueException + * + * @return \DateTime|FragmentInterface|string */ protected function formatDatetime(string $type, $value) { diff --git a/src/Schema/AbstractForeignKey.php b/src/Schema/AbstractForeignKey.php index 1bb67f72..8a3ead8f 100644 --- a/src/Schema/AbstractForeignKey.php +++ b/src/Schema/AbstractForeignKey.php @@ -122,9 +122,10 @@ public function getUpdateRule(): string * column one. * * @param array $columns + * * @return self */ - public function columns(array $columns): AbstractForeignKey + public function columns(array $columns): self { $this->columns = $columns; @@ -147,7 +148,7 @@ public function references( string $table, array $columns = ['id'], bool $forcePrefix = true - ): AbstractForeignKey { + ): self { $this->foreignTable = ($forcePrefix ? $this->tablePrefix : '') . $table; $this->foreignKeys = $columns; @@ -158,9 +159,10 @@ public function references( * Set foreign key delete behaviour. * * @param string $rule Possible values: NO ACTION, CASCADE, etc (driver specific). + * * @return self */ - public function onDelete(string $rule = self::NO_ACTION): AbstractForeignKey + public function onDelete(string $rule = self::NO_ACTION): self { $this->deleteRule = strtoupper($rule); @@ -171,9 +173,10 @@ public function onDelete(string $rule = self::NO_ACTION): AbstractForeignKey * Set foreign key update behaviour. * * @param string $rule Possible values: NO ACTION, CASCADE, etc (driver specific). + * * @return self */ - public function onUpdate(string $rule = self::NO_ACTION): AbstractForeignKey + public function onUpdate(string $rule = self::NO_ACTION): self { $this->updateRule = strtoupper($rule); @@ -184,6 +187,7 @@ public function onUpdate(string $rule = self::NO_ACTION): AbstractForeignKey * Foreign key creation syntax. * * @param DriverInterface $driver + * * @return string */ public function sqlStatement(DriverInterface $driver): string @@ -206,9 +210,10 @@ public function sqlStatement(DriverInterface $driver): string /** * @param AbstractForeignKey $initial + * * @return bool */ - public function compare(AbstractForeignKey $initial): bool + public function compare(self $initial): bool { // soft compare return $this == clone $initial; @@ -217,10 +222,11 @@ public function compare(AbstractForeignKey $initial): bool /** * @param DriverInterface $driver * @param array $columns + * * @return string */ protected function packColumns(DriverInterface $driver, array $columns): string { - return join(', ', array_map([$driver, 'identifier'], $columns)); + return implode(', ', array_map([$driver, 'identifier'], $columns)); } } diff --git a/src/Schema/AbstractIndex.php b/src/Schema/AbstractIndex.php index 72e64ac9..6f0d7d58 100644 --- a/src/Schema/AbstractIndex.php +++ b/src/Schema/AbstractIndex.php @@ -103,9 +103,10 @@ public function getColumnsWithSort(): array * Declare index type and behaviour to unique/non-unique state. * * @param bool $unique + * * @return self */ - public function unique(bool $unique = true): AbstractIndex + public function unique(bool $unique = true): self { $this->type = $unique ? self::UNIQUE : self::NORMAL; @@ -120,10 +121,11 @@ public function unique(bool $unique = true): AbstractIndex * $index->columns('key', 'key2'); * $index->columns(['key', 'key2']); * - * @param string|array $columns Columns array or comma separated list of parameters. + * @param array|string $columns Columns array or comma separated list of parameters. + * * @return self */ - public function columns($columns): AbstractIndex + public function columns($columns): self { if (!is_array($columns)) { $columns = func_get_args(); @@ -141,9 +143,10 @@ public function columns($columns): AbstractIndex * $index->sort(['key2' => 'DESC']); * * @param array $sort Associative array of columns to sort order. + * * @return self */ - public function sort(array $sort): AbstractIndex + public function sort(array $sort): self { $this->sort = $sort; @@ -155,6 +158,7 @@ public function sort(array $sort): AbstractIndex * * @param DriverInterface $driver * @param bool $includeTable Include table ON statement (not required for inline index creation). + * * @return string */ public function sqlStatement(DriverInterface $driver, bool $includeTable = true): string @@ -186,14 +190,14 @@ public function sqlStatement(DriverInterface $driver, bool $includeTable = true) /** * @param AbstractIndex $initial + * * @return bool */ - public function compare(AbstractIndex $initial): bool + public function compare(self $initial): bool { return $this == clone $initial; } - /** * Parse column name and order from column expression * @@ -211,18 +215,19 @@ public static function parseColumn($column) if (substr($column, -4) === ' ASC') { return [ substr($column, 0, strlen($column) - 4), - 'ASC' + 'ASC', ]; - } elseif (substr($column, -5) === ' DESC') { + } + if (substr($column, -5) === ' DESC') { return [ substr($column, 0, strlen($column) - 5), - 'DESC' + 'DESC', ]; } return [ $column, - null + null, ]; } } diff --git a/src/Schema/AbstractTable.php b/src/Schema/AbstractTable.php index 2bf3e15c..2cc2f426 100644 --- a/src/Schema/AbstractTable.php +++ b/src/Schema/AbstractTable.php @@ -56,8 +56,8 @@ abstract class AbstractTable implements TableInterface, ElementInterface /** * Table states. */ - public const STATUS_NEW = 0; - public const STATUS_EXISTS = 1; + public const STATUS_NEW = 0; + public const STATUS_EXISTS = 1; public const STATUS_DECLARED_DROPPED = 2; /** @@ -71,6 +71,7 @@ abstract class AbstractTable implements TableInterface, ElementInterface * Initial table state. * * @internal + * * @var State */ protected $initial; @@ -79,6 +80,7 @@ abstract class AbstractTable implements TableInterface, ElementInterface * Currently defined table state. * * @internal + * * @var State */ protected $current; @@ -128,6 +130,7 @@ public function __construct(DriverInterface $driver, string $name, string $prefi * Shortcut for column() method. * * @param string $column + * * @return AbstractColumn */ public function __get(string $column) @@ -145,6 +148,7 @@ public function __get(string $column) * * @param string $type * @param array $arguments Type specific parameters. + * * @return AbstractColumn */ public function __call(string $type, array $arguments) @@ -178,12 +182,12 @@ public function __clone() public function __debugInfo() { return [ - 'status' => $this->status, - 'full_name' => $this->getFullName(), - 'name' => $this->getName(), + 'status' => $this->status, + 'full_name' => $this->getFullName(), + 'name' => $this->getName(), 'primaryKeys' => $this->getPrimaryKeys(), - 'columns' => array_values($this->getColumns()), - 'indexes' => array_values($this->getIndexes()), + 'columns' => array_values($this->getColumns()), + 'indexes' => array_values($this->getIndexes()), 'foreignKeys' => array_values($this->getForeignKeys()), ]; } @@ -239,6 +243,7 @@ public function getStatus(): int * Sets table name. Use this function in combination with save to rename table. * * @param string $name + * * @return string Prefixed table name. */ public function setName(string $name): string @@ -295,9 +300,10 @@ public function declareDropped(): void * database might support compound indexes. * * @param array $columns + * * @return self */ - public function setPrimaryKeys(array $columns): AbstractTable + public function setPrimaryKeys(array $columns): self { //Originally i were forcing an exception when primary key were changed, now we should //force it when table will be synced @@ -392,6 +398,7 @@ public function getDependencies(): array * $table->column('name')->string(); * * @param string $name + * * @return AbstractColumn */ public function column(string $name): AbstractColumn @@ -423,10 +430,11 @@ public function column(string $name): AbstractColumn * $table->index(['key', 'key2']); * * @param array $columns List of index columns. - * @return AbstractIndex * * @throws SchemaException * @throws DriverException + * + * @return AbstractIndex */ public function index(array $columns): AbstractIndex { @@ -485,9 +493,10 @@ public function index(array $columns): AbstractIndex * name. * * @param array $columns - * @return AbstractForeignKey * * @throws SchemaException + * + * @return AbstractForeignKey */ public function foreignKey(array $columns): AbstractForeignKey { @@ -524,11 +533,12 @@ public function foreignKey(array $columns): AbstractForeignKey * * @param string $column * @param string $name New column name. - * @return self * * @throws SchemaException + * + * @return self */ - public function renameColumn(string $column, string $name): AbstractTable + public function renameColumn(string $column, string $name): self { if (!$this->hasColumn($column)) { throw new SchemaException( @@ -547,11 +557,12 @@ public function renameColumn(string $column, string $name): AbstractTable * * @param array $columns Index forming columns. * @param string $name New index name. - * @return self * * @throws SchemaException + * + * @return self */ - public function renameIndex(array $columns, string $name): AbstractTable + public function renameIndex(array $columns, string $name): self { if (!$this->hasIndex($columns)) { throw new SchemaException( @@ -569,11 +580,12 @@ public function renameIndex(array $columns, string $name): AbstractTable * Drop column by it's name. * * @param string $column - * @return self * * @throws SchemaException + * + * @return self */ - public function dropColumn(string $column): AbstractTable + public function dropColumn(string $column): self { $schema = $this->current->findColumn($column); if ($schema === null) { @@ -592,11 +604,12 @@ public function dropColumn(string $column): AbstractTable * Drop index by it's forming columns. * * @param array $columns - * @return self * * @throws SchemaException + * + * @return self */ - public function dropIndex(array $columns): AbstractTable + public function dropIndex(array $columns): self { $schema = $this->current->findIndex($columns); if ($schema === null) { @@ -615,11 +628,12 @@ public function dropIndex(array $columns): AbstractTable * Drop foreign key by it's name. * * @param array $columns - * @return self * * @throws SchemaException + * + * @return self */ - public function dropForeignKey(array $columns): AbstractTable + public function dropForeignKey(array $columns): self { $schema = $this->current->findForeignKey($columns); if ($schema === null) { @@ -651,9 +665,9 @@ public function getState(): State * * @param State $state Use null to flush table schema. * - * @return self|$this + * @return $this|self */ - public function setState(State $state = null): AbstractTable + public function setState(State $state = null): self { $this->current = new State($this->initial->getName()); @@ -668,9 +682,9 @@ public function setState(State $state = null): AbstractTable /** * Reset table state to it initial form. * - * @return self|$this + * @return $this|self */ - public function resetState(): AbstractTable + public function resetState(): self { $this->setState($this->initial); @@ -767,9 +781,10 @@ protected function prefixTableName(string $name): string * copy in order to prevent cross modifications. * * @param bool $withForeignKeys + * * @return AbstractTable */ - protected function normalizeSchema(bool $withForeignKeys = true): AbstractTable + protected function normalizeSchema(bool $withForeignKeys = true): self { // To make sure that no pre-sync modifications will be reflected on current table $target = clone $this; diff --git a/src/Schema/Reflector.php b/src/Schema/Reflector.php index 0ec4fa95..3b57e47f 100644 --- a/src/Schema/Reflector.php +++ b/src/Schema/Reflector.php @@ -22,7 +22,7 @@ */ final class Reflector { - public const STATE_NEW = 1; + public const STATE_NEW = 1; public const STATE_PASSED = 2; /** @var AbstractTable[] */ diff --git a/src/Schema/State.php b/src/Schema/State.php index 1f760588..efd599a0 100644 --- a/src/Schema/State.php +++ b/src/Schema/State.php @@ -137,6 +137,7 @@ public function getPrimaryKeys(): array /** * @param string $name + * * @return bool */ public function hasColumn(string $name): bool @@ -146,6 +147,7 @@ public function hasColumn(string $name): bool /** * @param array $columns + * * @return bool */ public function hasIndex(array $columns = []): bool @@ -155,6 +157,7 @@ public function hasIndex(array $columns = []): bool /** * @param array $columns + * * @return bool */ public function hasForeignKey(array $columns): bool @@ -190,9 +193,10 @@ public function registerForeignKey(AbstractForeignKey $reference): void * Drop column from table schema. * * @param AbstractColumn $column + * * @return self */ - public function forgetColumn(AbstractColumn $column): State + public function forgetColumn(AbstractColumn $column): self { foreach ($this->columns as $name => $columnSchema) { // todo: need better compare @@ -239,7 +243,8 @@ public function forgerForeignKey(AbstractForeignKey $foreignKey): void /** * @param string $name - * @return null|AbstractColumn + * + * @return AbstractColumn|null */ public function findColumn(string $name): ?AbstractColumn { @@ -256,7 +261,8 @@ public function findColumn(string $name): ?AbstractColumn * Find index by it's columns or return null. * * @param array $columns - * @return null|AbstractIndex + * + * @return AbstractIndex|null */ public function findIndex(array $columns): ?AbstractIndex { @@ -273,7 +279,8 @@ public function findIndex(array $columns): ?AbstractIndex * Find foreign key by it's column or return null. * * @param array $columns - * @return null|AbstractForeignKey + * + * @return AbstractForeignKey|null */ public function findForeignKey(array $columns): ?AbstractForeignKey { @@ -319,7 +326,7 @@ public function remountElements(): void * * @return self */ - public function syncState(State $source): self + public function syncState(self $source): self { $this->name = $source->name; $this->primaryKeys = $source->primaryKeys; diff --git a/src/Schema/Traits/ElementTrait.php b/src/Schema/Traits/ElementTrait.php index 666d5f66..9fd1ea2f 100644 --- a/src/Schema/Traits/ElementTrait.php +++ b/src/Schema/Traits/ElementTrait.php @@ -35,7 +35,8 @@ public function getTable(): string * Set element name. * * @param string $name - * @return self|$this + * + * @return $this|self */ public function setName(string $name): self { @@ -58,6 +59,7 @@ public function getName(): string * Element creation/definition syntax (specific to parent driver). * * @param Driver $driver + * * @return string */ abstract public function sqlStatement(Driver $driver): string; diff --git a/src/StatementInterface.php b/src/StatementInterface.php index a39fd074..0041ec0f 100644 --- a/src/StatementInterface.php +++ b/src/StatementInterface.php @@ -35,6 +35,7 @@ public function getQueryString(): string; * Must return the next row of a result set. * * @param int $mode + * * @return mixed */ public function fetch(int $mode = self::FETCH_ASSOC); @@ -43,6 +44,7 @@ public function fetch(int $mode = self::FETCH_ASSOC); * Must return a single column from the next row of a result set. * * @param int $columnNumber Optional column number. + * * @return mixed */ public function fetchColumn(int $columnNumber = null); @@ -51,6 +53,7 @@ public function fetchColumn(int $columnNumber = null); * Fetch all rows. * * @param int $mode Fetch mode. + * * @return array */ public function fetchAll(int $mode = self::FETCH_ASSOC): array; diff --git a/src/Table.php b/src/Table.php index c9131244..fe016be4 100644 --- a/src/Table.php +++ b/src/Table.php @@ -51,7 +51,7 @@ public function __construct(DatabaseInterface $database, string $name) * @param string $method * @param array $arguments * - * @return SelectQuery|mixed + * @return mixed|SelectQuery */ public function __call($method, array $arguments) { @@ -120,9 +120,10 @@ public function eraseData(): void * $table->insertOne(["name" => "Wolfy-J", "balance" => 10]); * * @param array $rowset - * @return int|string|null * * @throws BuilderException + * + * @return int|string|null */ public function insertOne(array $rowset = []) { @@ -262,6 +263,7 @@ public function getPrimaryKeys(): array * Check if table have specified column. * * @param string $name Column name. + * * @return bool */ public function hasColumn(string $name): bool @@ -283,6 +285,7 @@ public function getColumns(): array * Check if table has index related to set of provided columns. Columns order does matter! * * @param array $columns + * * @return bool */ public function hasIndex(array $columns = []): bool @@ -304,6 +307,7 @@ public function getIndexes(): array * Check if table has foreign key related to table column. * * @param array $columns Column names. + * * @return bool */ public function hasForeignKey(array $columns): bool diff --git a/src/TableInterface.php b/src/TableInterface.php index 95edea2a..bbb20f30 100644 --- a/src/TableInterface.php +++ b/src/TableInterface.php @@ -49,6 +49,7 @@ public function getPrimaryKeys(): array; * Check if table have specified column. * * @param string $name Column name. + * * @return bool */ public function hasColumn(string $name): bool; @@ -64,6 +65,7 @@ public function getColumns(): array; * Check if table has index related to set of provided columns. Columns order does matter! * * @param array $columns + * * @return bool */ public function hasIndex(array $columns = []): bool; @@ -79,6 +81,7 @@ public function getIndexes(): array; * Check if table has foreign key related to table column. * * @param array $columns Column names. + * * @return bool */ public function hasForeignKey(array $columns): bool; diff --git a/tests/Database/BaseTest.php b/tests/Database/BaseTest.php index c709b43d..5f897858 100644 --- a/tests/Database/BaseTest.php +++ b/tests/Database/BaseTest.php @@ -26,8 +26,8 @@ abstract class BaseTest extends TestCase { - use TableAssertions; use Loggable; + use TableAssertions; public const DRIVER = null; @@ -59,10 +59,10 @@ public function getDriver(): Driver $options = [ 'connection' => $config['conn'], - 'username' => $config['user'], - 'password' => $config['pass'], - 'options' => [], - 'queryCache' => true + 'username' => $config['user'], + 'password' => $config['pass'], + 'options' => [], + 'queryCache' => true, ]; if (isset($config['schema'])) { @@ -102,7 +102,7 @@ protected function db(string $name = 'default', string $prefix = '') * Send sample query in a form where all quotation symbols replaced with { and }. * * @param string $query - * @param string|FragmentInterface $fragment + * @param FragmentInterface|string $fragment */ protected function assertSameQuery(string $query, $fragment): void { @@ -151,6 +151,7 @@ protected function dropDatabase(Database $database = null): void /** * @param AbstractTable $table + * * @return AbstractTable */ protected function fetchSchema(AbstractTable $table): AbstractTable @@ -179,7 +180,7 @@ protected function makeMessage(string $table, Comparator $comparator) print_r($pair); } - return "Table '{$table}' not synced, column(s) '" . join( + return "Table '{$table}' not synced, column(s) '" . implode( "', '", $names ) . "' have been changed."; diff --git a/tests/Database/ConfigTest.php b/tests/Database/ConfigTest.php index 84003ef9..cfa0f888 100644 --- a/tests/Database/ConfigTest.php +++ b/tests/Database/ConfigTest.php @@ -21,7 +21,7 @@ public function testDefaultDatabase(): void { $config = new DatabaseConfig( [ - 'default' => 'database-1' + 'default' => 'database-1', ] ); @@ -32,11 +32,11 @@ public function testHasDatabase(): void { $config = new DatabaseConfig( [ - 'default' => 'database-1', + 'default' => 'database-1', 'databases' => [ - 'test' => [], + 'test' => [], 'test2' => [], - ] + ], ] ); @@ -49,11 +49,11 @@ public function testDatabaseException(): void { $config = new DatabaseConfig( [ - 'default' => 'database-1', + 'default' => 'database-1', 'databases' => [ - 'test' => [], + 'test' => [], 'test2' => [], - ] + ], ] ); @@ -66,15 +66,15 @@ public function testDatabaseDriver(): void { $config = new DatabaseConfig( [ - 'default' => 'database-1', + 'default' => 'database-1', 'databases' => [ - 'test' => [ - 'connection' => 'abc' + 'test' => [ + 'connection' => 'abc', ], 'test2' => [ - 'write' => 'bce' + 'write' => 'bce', ], - ] + ], ] ); @@ -86,20 +86,20 @@ public function testDatabaseReadDriver(): void { $config = new DatabaseConfig( [ - 'default' => 'database-1', + 'default' => 'database-1', 'databases' => [ - 'test' => [ - 'connection' => 'dce', - 'readConnection' => 'abc' + 'test' => [ + 'connection' => 'dce', + 'readConnection' => 'abc', ], 'test1' => [ - 'connection' => 'abc' + 'connection' => 'abc', ], 'test2' => [ 'write' => 'dce', - 'read' => 'bce' + 'read' => 'bce', ], - ] + ], ] ); @@ -112,20 +112,20 @@ public function testDatabasePrefix(): void { $config = new DatabaseConfig( [ - 'default' => 'database-1', + 'default' => 'database-1', 'databases' => [ - 'test' => [ + 'test' => [ 'tablePrefix' => 'abc', - 'driver' => 'test' + 'driver' => 'test', ], 'test2' => [ 'tablePrefix' => 'bce', - 'driver' => 'test' + 'driver' => 'test', ], 'test3' => [ - 'driver' => 'test' - ] - ] + 'driver' => 'test', + ], + ], ] ); @@ -139,15 +139,15 @@ public function testDatabaseNames(): void { $config = new DatabaseConfig( [ - 'default' => 'database-1', + 'default' => 'database-1', 'databases' => [ - 'test' => [ - 'driver' => 'test' + 'test' => [ + 'driver' => 'test', ], 'test2' => [ - 'driver' => 'test' + 'driver' => 'test', ], - ] + ], ] ); @@ -158,19 +158,19 @@ public function testAliases(): void { $config = new DatabaseConfig( [ - 'default' => 'database-1', - 'aliases' => [ + 'default' => 'database-1', + 'aliases' => [ 'test3' => 'test2', //Recursive 'test6' => 'test5', 'test5' => 'test4', - 'test4' => 'test' + 'test4' => 'test', ], 'databases' => [ - 'test' => [], + 'test' => [], 'test2' => [], - ] + ], ] ); @@ -192,9 +192,9 @@ public function testHasDriver(): void $config = new DatabaseConfig( [ 'connections' => [ - 'test' => [], + 'test' => [], 'test2' => [], - ] + ], ] ); @@ -205,9 +205,9 @@ public function testHasDriver(): void $config = new DatabaseConfig( [ 'drivers' => [ - 'test' => [], + 'test' => [], 'test2' => [], - ] + ], ] ); @@ -234,18 +234,18 @@ public function testGetDriver(): void $config = new DatabaseConfig( [ 'connections' => [ - 'test' => [ + 'test' => [ 'driver' => 'abc', - 'option' => 'option' + 'option' => 'option', ], 'test2' => [ - 'driver' => 'bce', + 'driver' => 'bce', 'options' => [ - 'option' - ] + 'option', + ], ], - 'test3' => new Autowire('someDriver') - ] + 'test3' => new Autowire('someDriver'), + ], ] ); @@ -259,18 +259,18 @@ public function testDriverNames(): void $config = new DatabaseConfig( [ 'connections' => [ - 'test' => [ + 'test' => [ 'driver' => 'abc', - 'option' => 'option' + 'option' => 'option', ], 'test2' => [ - 'driver' => 'bce', + 'driver' => 'bce', 'options' => [ - 'option' - ] + 'option', + ], ], - 'test3' => new Autowire('someDriver') - ] + 'test3' => new Autowire('someDriver'), + ], ] ); diff --git a/tests/Database/ConsistencyTest.php b/tests/Database/ConsistencyTest.php index bea932c4..e9731d95 100644 --- a/tests/Database/ConsistencyTest.php +++ b/tests/Database/ConsistencyTest.php @@ -363,13 +363,13 @@ public function testUuid(): void $this->database->table('table')->insertOne( [ - 'target' => 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11' + 'target' => 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11', ] ); $this->assertEquals( [ - 'target' => 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11' + 'target' => 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11', ], $this->database->table('table')->select()->fetchAll()[0] ); @@ -393,13 +393,13 @@ public function testUuidPrimary(): void $this->database->table('table')->insertOne( [ - 'target' => 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11' + 'target' => 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11', ] ); $this->assertEquals( [ - 'target' => 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11' + 'target' => 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11', ], $this->database->table('table')->select()->fetchAll()[0] ); diff --git a/tests/Database/DatabaseTest.php b/tests/Database/DatabaseTest.php index 19b74847..8d2533cc 100644 --- a/tests/Database/DatabaseTest.php +++ b/tests/Database/DatabaseTest.php @@ -72,7 +72,6 @@ public function testExecute(): void $this->assertSame(1, $db->execute('test', ['param'])); } - public function testPrefix(): void { $db = $this->db(); diff --git a/tests/Database/Driver/Postgres/AlterColumnsWithSchemaTest.php b/tests/Database/Driver/Postgres/AlterColumnsWithSchemaTest.php index ef4c1748..a684c537 100644 --- a/tests/Database/Driver/Postgres/AlterColumnsWithSchemaTest.php +++ b/tests/Database/Driver/Postgres/AlterColumnsWithSchemaTest.php @@ -17,8 +17,8 @@ class AlterColumnsWithSchemaTest extends TestCase { use Helpers; - use TableAssertions; use Loggable; + use TableAssertions; /** @var Database */ private $db; diff --git a/tests/Database/Driver/Postgres/CreateTableWithSchema.php b/tests/Database/Driver/Postgres/CreateTableWithSchema.php index 10eed317..e694f7af 100644 --- a/tests/Database/Driver/Postgres/CreateTableWithSchema.php +++ b/tests/Database/Driver/Postgres/CreateTableWithSchema.php @@ -40,7 +40,7 @@ public function testCreatesWithPublicSchema(): void $this->createTable($driver, 'schema1.test'); $this->assertSame([ - 'public.test', 'postgres.test', 'schema1.test' + 'public.test', 'postgres.test', 'schema1.test', ], $driver->getSchemaHandler()->getTableNames()); } diff --git a/tests/Database/Driver/Postgres/DriverTest.php b/tests/Database/Driver/Postgres/DriverTest.php index 2c49829c..4348bbed 100644 --- a/tests/Database/Driver/Postgres/DriverTest.php +++ b/tests/Database/Driver/Postgres/DriverTest.php @@ -13,9 +13,9 @@ public function testIfSchemaOptionsDoesNotPresentUsePublicSchema(): void { $driver = new PostgresDriver([ 'connection' => 'pgsql:host=127.0.0.1;port=15432;dbname=spiral', - 'username' => 'postgres', - 'password' => 'postgres', - 'schema' => ['$user', 'public'] + 'username' => 'postgres', + 'password' => 'postgres', + 'schema' => ['$user', 'public'], ]); $driver->connect(); @@ -27,10 +27,10 @@ public function testIfSchemaOptionsDoesNotPresentUsePublicSchema(): void public function testDefaultSchemaCanBeDefined(): void { $driver = new PostgresDriver([ - 'connection' => 'pgsql:host=127.0.0.1;port=15432;dbname=spiral', - 'username' => 'postgres', - 'password' => 'postgres', - 'default_schema' => 'private' + 'connection' => 'pgsql:host=127.0.0.1;port=15432;dbname=spiral', + 'username' => 'postgres', + 'password' => 'postgres', + 'default_schema' => 'private', ]); $driver->connect(); @@ -43,9 +43,9 @@ public function testDefaultSchemaCanBeDefinedFromAvailableSchemas(): void { $driver = new PostgresDriver([ 'connection' => 'pgsql:host=127.0.0.1;port=15432;dbname=spiral', - 'username' => 'postgres', - 'password' => 'postgres', - 'schema' => 'private' + 'username' => 'postgres', + 'password' => 'postgres', + 'schema' => 'private', ]); $driver->connect(); @@ -57,11 +57,11 @@ public function testDefaultSchemaCanBeDefinedFromAvailableSchemas(): void public function testDefaultSchemaCanNotBeRedefinedFromAvailableSchemas(): void { $driver = new PostgresDriver([ - 'connection' => 'pgsql:host=127.0.0.1;port=15432;dbname=spiral', - 'username' => 'postgres', - 'password' => 'postgres', + 'connection' => 'pgsql:host=127.0.0.1;port=15432;dbname=spiral', + 'username' => 'postgres', + 'password' => 'postgres', 'default_schema' => 'private', - 'schema' => ['test', 'private'] + 'schema' => ['test', 'private'], ]); $driver->connect(); @@ -73,11 +73,11 @@ public function testDefaultSchemaCanNotBeRedefinedFromAvailableSchemas(): void public function testDefaultSchemaForCurrentUser(): void { $driver = new PostgresDriver([ - 'connection' => 'pgsql:host=127.0.0.1;port=15432;dbname=spiral', - 'username' => 'postgres', - 'password' => 'postgres', + 'connection' => 'pgsql:host=127.0.0.1;port=15432;dbname=spiral', + 'username' => 'postgres', + 'password' => 'postgres', 'default_schema' => '$user', - 'schema' => ['test', 'private'] + 'schema' => ['test', 'private'], ]); $driver->connect(); @@ -93,9 +93,9 @@ public function testIfSchemaOptionsPresentsUseIt($schema, $available, $result): { $driver = new PostgresDriver([ 'connection' => 'pgsql:host=127.0.0.1;port=15432;dbname=spiral', - 'username' => 'postgres', - 'password' => 'postgres', - 'schema' => $schema + 'username' => 'postgres', + 'password' => 'postgres', + 'schema' => $schema, ]); $this->assertSame($available, $driver->getSearchSchemas()); @@ -108,7 +108,7 @@ public function schemaProvider() return [ ['private', ['private'], 'private'], [['schema1', 'schema2'], ['schema1', 'schema2'], 'schema1, schema2'], - [['$user', 'schema2'], ['postgres', 'schema2'], '"$user", schema2'] + [['$user', 'schema2'], ['postgres', 'schema2'], '"$user", schema2'], ]; } } diff --git a/tests/Database/Driver/Postgres/Helpers.php b/tests/Database/Driver/Postgres/Helpers.php index 2b320ebc..5fd87e46 100644 --- a/tests/Database/Driver/Postgres/Helpers.php +++ b/tests/Database/Driver/Postgres/Helpers.php @@ -53,6 +53,7 @@ protected function setUpSchemas(): void /** * @param AbstractTable $table + * * @return AbstractTable */ protected function fetchSchema(AbstractTable $table): AbstractTable @@ -76,8 +77,8 @@ private function getDriver($schema = null, string $defaultSchema = null): Driver { $options = [ 'connection' => 'pgsql:host=127.0.0.1;port=15432;dbname=spiral', - 'username' => 'postgres', - 'password' => 'postgres' + 'username' => 'postgres', + 'password' => 'postgres', ]; if ($schema) { diff --git a/tests/Database/Driver/Postgres/InsertQueryTest.php b/tests/Database/Driver/Postgres/InsertQueryTest.php index 92f0ad52..067b9310 100644 --- a/tests/Database/Driver/Postgres/InsertQueryTest.php +++ b/tests/Database/Driver/Postgres/InsertQueryTest.php @@ -46,7 +46,7 @@ public function testSimpleInsert(): void { $insert = $this->database->insert()->into('target_table')->values( [ - 'name' => 'Anton' + 'name' => 'Anton', ] ); @@ -56,7 +56,6 @@ public function testSimpleInsert(): void ); } - public function testSimpleInsertWithStatesValues(): void { $insert = $this->database->insert()->into('target_table') diff --git a/tests/Database/Driver/Postgres/TableTest.php b/tests/Database/Driver/Postgres/TableTest.php index 3ffd6405..bfcf38ab 100644 --- a/tests/Database/Driver/Postgres/TableTest.php +++ b/tests/Database/Driver/Postgres/TableTest.php @@ -26,9 +26,9 @@ public function testGetColumns(): void $this->assertSame(0, $table->count()); $expected = [ - 'id' => 'primary', - 'name' => 'text', - 'value' => 'integer' + 'id' => 'primary', + 'name' => 'text', + 'value' => 'integer', ]; arsort($expected); @@ -53,7 +53,7 @@ public function testSelectDistinct(): void ['Anton', 10], ['Anton', 20], ['Bob', 15], - ['Charlie', 10] + ['Charlie', 10], ] ); @@ -72,7 +72,7 @@ public function testSelectDistinctOn(): void ['Anton', 10], ['Anton', 20], ['Bob', 15], - ['Charlie', 10] + ['Charlie', 10], ] ); diff --git a/tests/Database/Driver/SQLServer/SelectQueryTest.php b/tests/Database/Driver/SQLServer/SelectQueryTest.php index 33b6f219..16aa5ad4 100644 --- a/tests/Database/Driver/SQLServer/SelectQueryTest.php +++ b/tests/Database/Driver/SQLServer/SelectQueryTest.php @@ -34,7 +34,7 @@ public function testLimitNoOffset(): void $this->assertSameParameters( [ 1, - 10 + 10, ], $select ); @@ -55,7 +55,7 @@ public function testLimitAndOffset(): void $this->assertSameParameters( [ 21, - 30 + 30, ], $select ); @@ -78,7 +78,7 @@ public function testLimitAndOffsetAndOrderBy(): void $this->assertSameParameters( [ 20, - 10 + 10, ], $select ); @@ -98,7 +98,7 @@ public function testOffsetNoLimit(): void $this->assertSameParameters( [ - 21 + 21, ], $select ); diff --git a/tests/Database/Driver/SQLServer/StatementTest.php b/tests/Database/Driver/SQLServer/StatementTest.php index 81bca4ef..66e48b6e 100644 --- a/tests/Database/Driver/SQLServer/StatementTest.php +++ b/tests/Database/Driver/SQLServer/StatementTest.php @@ -49,11 +49,11 @@ public function testToArray(): void $this->assertEquals( [ [ - 'id' => 1, - 'name' => md5('0'), - 'value' => 0, - SQLServerCompiler::ROW_NUMBER => 1 - ] + 'id' => 1, + 'name' => md5('0'), + 'value' => 0, + SQLServerCompiler::ROW_NUMBER => 1, + ], ], $result->fetchAll() ); diff --git a/tests/Database/Driver/SQLServer/TableTest.php b/tests/Database/Driver/SQLServer/TableTest.php index c6b7fb98..a7f913b5 100644 --- a/tests/Database/Driver/SQLServer/TableTest.php +++ b/tests/Database/Driver/SQLServer/TableTest.php @@ -30,7 +30,7 @@ public function testAggregationAvgByPassFloat(): void ['Anton', 10], ['John', 20], ['Bob', 15], - ['Charlie', 10] + ['Charlie', 10], ] ); @@ -58,7 +58,7 @@ public function testAggregationAvgByPassRealFloat(): void ['Anton', 10], ['John', 20], ['Bob', 15], - ['Charlie', 10] + ['Charlie', 10], ] ); diff --git a/tests/Database/Driver/SQLite/SelectQueryTest.php b/tests/Database/Driver/SQLite/SelectQueryTest.php index 3e4978a5..d492d925 100644 --- a/tests/Database/Driver/SQLite/SelectQueryTest.php +++ b/tests/Database/Driver/SQLite/SelectQueryTest.php @@ -30,7 +30,7 @@ public function testOffsetNoLimit(): void $this->assertSameParameters( [ - 20 + 20, ], $select ); diff --git a/tests/Database/FragmentTest.php b/tests/Database/FragmentTest.php index 071120f6..03712fe9 100644 --- a/tests/Database/FragmentTest.php +++ b/tests/Database/FragmentTest.php @@ -68,7 +68,7 @@ public function testSetState(): void $this->assertSame( [ 'expression' => 'some sql', - 'parameters' => [] + 'parameters' => [], ], $exp->getTokens() ); @@ -79,7 +79,7 @@ public function testSetState(): void $this->assertSame( [ 'fragment' => 'some sql', - 'parameters' => [] + 'parameters' => [], ], $f->getTokens() ); diff --git a/tests/Database/InterpolatorTest.php b/tests/Database/InterpolatorTest.php index d198c7f3..96c04a2d 100644 --- a/tests/Database/InterpolatorTest.php +++ b/tests/Database/InterpolatorTest.php @@ -42,7 +42,7 @@ public function testDatesInterpolation(): void $query = 'SELECT * FROM table WHERE name = :name AND registered > :registered'; $parameters = [ - ':name' => new Parameter('Anton'), + ':name' => new Parameter('Anton'), ':registered' => new Parameter($date = new \DateTime('now')), ]; @@ -60,7 +60,7 @@ public function testDateInterpolationWithDateTimeImmutable(): void $query = 'SELECT * FROM table WHERE name = :name AND registered > :registered'; $parameters = [ - ':name' => new Parameter('Anton'), + ':name' => new Parameter('Anton'), ':registered' => new Parameter($date = new \DateTimeImmutable('now')), ]; diff --git a/tests/Database/ManagerTest.php b/tests/Database/ManagerTest.php index 5792ed55..504a2ae2 100644 --- a/tests/Database/ManagerTest.php +++ b/tests/Database/ManagerTest.php @@ -25,15 +25,15 @@ class ManagerTest extends TestCase { public const DEFAULT_OPTIONS = [ - 'default' => 'default', - 'databases' => [ + 'default' => 'default', + 'databases' => [ 'default' => [ 'prefix' => 'prefix_', - 'read' => 'read', - 'write' => 'write' - ] + 'read' => 'read', + 'write' => 'write', + ], ], - 'connections' => [] + 'connections' => [], ]; public function testAddDatabase(): void @@ -189,25 +189,25 @@ public function testConfigured(): void $dbal = new DatabaseManager( new DatabaseConfig( [ - 'default' => 'default', - 'databases' => [ + 'default' => 'default', + 'databases' => [ 'default' => [ - 'driver' => 'default' + 'driver' => 'default', ], - 'test' => [ - 'driver' => 'default' + 'test' => [ + 'driver' => 'default', ], ], 'connections' => [ 'default' => [ - 'driver' => SQLiteDriver::class, + 'driver' => SQLiteDriver::class, 'options' => [ 'connection' => 'sqlite::memory:', - 'username' => 'sqlite', - 'password' => '' - ] - ] - ] + 'username' => 'sqlite', + 'password' => '', + ], + ], + ], ] ) ); @@ -221,25 +221,25 @@ public function testCountDrivers(): void $dbal = new DatabaseManager( new DatabaseConfig( [ - 'default' => 'default', - 'databases' => [ + 'default' => 'default', + 'databases' => [ 'default' => [ - 'driver' => 'default' + 'driver' => 'default', ], - 'test' => [ - 'driver' => 'default' + 'test' => [ + 'driver' => 'default', ], ], 'connections' => [ 'default' => [ - 'driver' => SQLiteDriver::class, + 'driver' => SQLiteDriver::class, 'options' => [ 'connection' => 'sqlite::memory:', - 'username' => 'sqlite', - 'password' => '' - ] - ] - ] + 'username' => 'sqlite', + 'password' => '', + ], + ], + ], ] ) ); @@ -252,23 +252,23 @@ public function testCountDatabase(): void $dbal = new DatabaseManager( new DatabaseConfig( [ - 'default' => 'default', - 'databases' => [ + 'default' => 'default', + 'databases' => [ 'default' => [ - 'driver' => 'default' + 'driver' => 'default', ], - 'test' => [ - 'driver' => 'default' + 'test' => [ + 'driver' => 'default', ], ], 'connections' => [ 'default' => [ - 'driver' => SQLiteDriver::class, + 'driver' => SQLiteDriver::class, 'connection' => 'sqlite::memory:', - 'username' => 'sqlite', - 'password' => '' - ] - ] + 'username' => 'sqlite', + 'password' => '', + ], + ], ] ) ); @@ -287,8 +287,8 @@ public function testBadDriver(): void $dbal = new DatabaseManager( new DatabaseConfig([ 'connections' => [ - 'default' => new Container\Autowire('unknown') - ] + 'default' => new Container\Autowire('unknown'), + ], ]) ); diff --git a/tests/Database/NestedQueriesTest.php b/tests/Database/NestedQueriesTest.php index f2c508f5..6bf1c764 100644 --- a/tests/Database/NestedQueriesTest.php +++ b/tests/Database/NestedQueriesTest.php @@ -42,7 +42,7 @@ public function testSubQuery(): void [ 'user', true, - 100 + 100, ], $select ); @@ -71,7 +71,7 @@ public function testSubQueryPrefixed(): void [ 'user', true, - 100 + 100, ], $select ); @@ -103,7 +103,7 @@ public function testSubQueryPrefixedAsIndentifier(): void 'user', true, 12, - 100 + 100, ], $select ); @@ -135,7 +135,7 @@ public function testSubQueryPrefixedRawIdentifier(): void 'user', true, 12, - 100 + 100, ], $select ); @@ -165,13 +165,12 @@ public function testSubQueryPrefixedRaw(): void [ 'user', true, - 100 + 100, ], $select ); } - public function testSubQueryPrefixedWithExpression(): void { $select = $this->db('prefixed', 'prefix_')->select() @@ -197,13 +196,12 @@ public function testSubQueryPrefixedWithExpression(): void [ 'user', true, - 100 + 100, ], $select ); } - public function testSubQueryPrefixedWithExpressionId(): void { $select = $this->db('prefixed', 'prefix_')->select() @@ -231,7 +229,7 @@ public function testSubQueryPrefixedWithExpressionId(): void 'user', true, 0, - 100 + 100, ], $select ); @@ -263,7 +261,7 @@ public function testUnionWithPrefixes(): void 'user', 100, 'admin', - 800 + 800, ], $select ); @@ -295,7 +293,7 @@ public function testUnionWithPrefixes1(): void 'user', 100, 'admin', - 800 + 800, ], $select ); @@ -337,7 +335,7 @@ public function testUnionWithPrefixes2(): void 800, 8, 9, - 10 + 10, ], $select ); @@ -381,7 +379,7 @@ public function testSubQueryInUpdate(): void 'open', 'user', true, - 100 + 100, ], $select ); diff --git a/tests/Database/ParameterTest.php b/tests/Database/ParameterTest.php index 45272afe..c044ea74 100644 --- a/tests/Database/ParameterTest.php +++ b/tests/Database/ParameterTest.php @@ -79,7 +79,7 @@ public function testDebugInfo(): void $this->assertSame( [ 'value' => [1, 2, 3], - 'type' => \PDO::PARAM_STR + 'type' => \PDO::PARAM_STR, ], $parameter->__debugInfo() ); diff --git a/tests/Database/QuoterTest.php b/tests/Database/QuoterTest.php index 4149bcc6..2f6f73ba 100644 --- a/tests/Database/QuoterTest.php +++ b/tests/Database/QuoterTest.php @@ -346,6 +346,7 @@ public function testSQLServerPrefixes(): void /** * @param string $prefix * @param string $quote + * * @return Quoter */ protected function makeQuoter($prefix = '', string $quote = '""') diff --git a/tests/Database/SelectQueryTest.php b/tests/Database/SelectQueryTest.php index 3356778b..9639f56f 100644 --- a/tests/Database/SelectQueryTest.php +++ b/tests/Database/SelectQueryTest.php @@ -66,7 +66,7 @@ public function testSimpleWhere(): void $this->assertSameQuery('SELECT * FROM {table} WHERE {id} = ?', $select); $this->assertSameParameters( [ - 1 + 1, ], $select ); @@ -86,7 +86,7 @@ public function testWhereAndJoin(): void $this->assertSameParameters( [ 'test', - 1 + 1, ], $select ); @@ -107,7 +107,7 @@ public function testWhereAndJoinReverted(): void $this->assertSameParameters( [ 'test', - 1 + 1, ], $select ); @@ -125,7 +125,7 @@ public function testArrayWhere(): void 1, 2, 3, - 4 + 4, ], $select ); @@ -154,7 +154,7 @@ public function testCompileNestedQuery(): void $this->assertSameParameters( [ 'Antony', - 123 + 123, ], $select ); @@ -176,7 +176,6 @@ public function testSelectFromSelect(): void [ 100, 'Antony', - ], $select ); @@ -251,7 +250,6 @@ static function (): void { ); } - public function testSelectWithSimpleWhereNotNull(): void { $select = $this->database->select()->distinct()->from(['users'])->where('name', '!=', null); @@ -428,7 +426,7 @@ static function (SelectQuery $select): void { [ 'Anton', 10, - 1000 + 1000, ], $select ); @@ -512,8 +510,8 @@ public function testShortWhereWithCondition(): void [ 'name' => [ 'like' => 'Anton', - '!=' => 'Antony' - ] + '!=' => 'Antony', + ], ] ); @@ -531,8 +529,8 @@ public function testShortWhereWithBetweenCondition(): void ->where( [ 'value' => [ - 'between' => [1, 2] - ] + 'between' => [1, 2], + ], ] ); @@ -550,8 +548,8 @@ public function testShortWhereWithNotBetweenCondition(): void ->where( [ 'value' => [ - 'not between' => [1, 2] - ] + 'not between' => [1, 2], + ], ] ); @@ -572,8 +570,8 @@ public function testShortWhereWithBetweenConditionBadArguments(): void ->where( [ 'value' => [ - 'between' => [1] - ] + 'between' => [1], + ], ] ); } @@ -585,8 +583,8 @@ public function testShortWhereMultiple(): void ->from(['users']) ->where( [ - 'name' => 'Anton', - 'value' => 1 + 'name' => 'Anton', + 'value' => 1, ] ); @@ -634,8 +632,8 @@ public function testAndShortWhereOR(): void [ '@or' => [ ['value' => 1], - ['value' => ['>' => 12]] - ] + ['value' => ['>' => 12]], + ], ] ); @@ -655,8 +653,8 @@ public function testOrShortWhereOR(): void [ '@or' => [ ['value' => 1], - ['value' => ['>' => 12]] - ] + ['value' => ['>' => 12]], + ], ] ); @@ -676,8 +674,8 @@ public function testAndShortWhereAND(): void [ '@and' => [ ['value' => 1], - ['value' => ['>' => 12]] - ] + ['value' => ['>' => 12]], + ], ] ); @@ -687,7 +685,6 @@ public function testAndShortWhereAND(): void ); } - public function testOrShortWhereAND(): void { $select = $this->database @@ -698,8 +695,8 @@ public function testOrShortWhereAND(): void [ '@and' => [ ['value' => 1], - ['value' => ['>' => 12]] - ] + ['value' => ['>' => 12]], + ], ] ); @@ -719,7 +716,7 @@ public function testBadShortExpression(): void ->from(['users']) ->where( [ - 'status' => ['active', 'blocked'] + 'status' => ['active', 'blocked'], ] ); } @@ -850,7 +847,7 @@ public function testMultipleOrderByViaArray(): void ->orderBy( [ 'value' => SelectQuery::SORT_ASC, - 'name' => SelectQuery::SORT_DESC + 'name' => SelectQuery::SORT_DESC, ] ); @@ -999,7 +996,6 @@ public function testAllColumns1(): void ); } - public function testAllColumns2(): void { $select = $this->database @@ -1411,8 +1407,8 @@ public function testHavingShortHavingWithCondition(): void [ 'name' => [ 'like' => 'Anton', - '!=' => 'Antony' - ] + '!=' => 'Antony', + ], ] ); @@ -1429,8 +1425,8 @@ public function testHavingShortHavingWithBetweenCondition(): void ->having( [ 'value' => [ - 'between' => [1, 2] - ] + 'between' => [1, 2], + ], ] ); @@ -1447,8 +1443,8 @@ public function testHavingShortHavingWithNotBetweenCondition(): void ->having( [ 'value' => [ - 'not between' => [1, 2] - ] + 'not between' => [1, 2], + ], ] ); @@ -1468,21 +1464,20 @@ public function testHavingShortHavingWithBetweenConditionBadArguments(): void ->having( [ 'value' => [ - 'between' => [1] - ] + 'between' => [1], + ], ] ); } - public function testHavingShortHavingMultiple(): void { $select = $this->database->select() ->from(['users']) ->having( [ - 'name' => 'Anton', - 'value' => 1 + 'name' => 'Anton', + 'value' => 1, ] ); @@ -1527,8 +1522,8 @@ public function testHavingAndShortHavingOR(): void [ '@or' => [ ['value' => 1], - ['value' => ['>' => 12]] - ] + ['value' => ['>' => 12]], + ], ] ); @@ -1547,8 +1542,8 @@ public function testHavingOrShortHavingOR(): void [ '@or' => [ ['value' => 1], - ['value' => ['>' => 12]] - ] + ['value' => ['>' => 12]], + ], ] ); @@ -1567,8 +1562,8 @@ public function testHavingAndShortHavingAND(): void [ '@and' => [ ['value' => 1], - ['value' => ['>' => 12]] - ] + ['value' => ['>' => 12]], + ], ] ); @@ -1587,8 +1582,8 @@ public function testHavingOrShortHavingAND(): void [ '@and' => [ ['value' => 1], - ['value' => ['>' => 12]] - ] + ['value' => ['>' => 12]], + ], ] ); @@ -1611,7 +1606,7 @@ public function testLimitNoOffset(): void $this->assertSameParameters( [ - 10 + 10, ], $select ); @@ -1630,13 +1625,12 @@ public function testLimitAndOffset(): void $this->assertSameParameters( [ 10, - 20 + 20, ], $select ); } - public function testOffsetNoLimit(): void { $select = $this->database->select()->from(['users'])->offset(20); @@ -1648,7 +1642,7 @@ public function testOffsetNoLimit(): void $this->assertSameParameters( [ - 20 + 20, ], $select ); @@ -1671,7 +1665,7 @@ public function testLimitAndOffsetAndOrderBy(): void $this->assertSameParameters( [ 10, - 20 + 20, ], $select ); @@ -1846,7 +1840,7 @@ public function testShortWhereValueAsExpressionPrefixed(): void $select = $this->db('prefixed', 'prefix_')->select()->from(['users']) ->where( [ - 'balance' => ['>' => new Expression('users.origin_balance')] + 'balance' => ['>' => new Expression('users.origin_balance')], ] ); @@ -1879,7 +1873,6 @@ public function testGroupByExpression(): void ); } - public function testGroupByExpressionWithPrefix(): void { $select = $this->db('prefixed', 'prefix_')->select() @@ -1941,7 +1934,7 @@ public function testBadArrayParameterInShortWhere(): void ->from(['users']) ->where( [ - 'status' => ['IN' => ['active', 'blocked']] + 'status' => ['IN' => ['active', 'blocked']], ] ); } @@ -1975,7 +1968,7 @@ public function testGoodArrayParameterInShortWhere(): void ->from(['users']) ->where( [ - 'status' => ['IN' => $p] + 'status' => ['IN' => $p], ] ); @@ -2256,7 +2249,7 @@ public function testJoinAliases(): void ->on( [ 'p.user_id' => 'users.id', - 'p.public' => new Parameter(true) + 'p.public' => new Parameter(true), ] ); @@ -2275,7 +2268,7 @@ public function testJoinAliasesWithPrefixes(): void ->on( [ 'p.user_id' => 'users.id', - 'p.public' => new Parameter(true) + 'p.public' => new Parameter(true), ] ); @@ -2294,7 +2287,7 @@ public function testJoinAliasesWithPrefixesAlternative(): void ->on( [ 'p.user_id' => 'users.id', - 'p.public' => new Parameter(true) + 'p.public' => new Parameter(true), ] ); @@ -2313,7 +2306,7 @@ public function testJoinAliasesWithPrefixesAndAliases(): void ->on( [ 'p.user_id' => 'u.id', - 'p.public' => new Parameter(true) + 'p.public' => new Parameter(true), ] ); @@ -2422,7 +2415,7 @@ public function testSelectWithParametricExpression(): void $this->assertSameParameters( [ 'Antony', - 10 + 10, ], $select ); @@ -2448,7 +2441,7 @@ public function testSelectWithParametricExpression2(): void 101, 102, 103, - 104 + 104, ], $select ); @@ -2475,7 +2468,7 @@ public function testSelectWithParametricExpression3(): void 102, 600, 103, - 104 + 104, ], $select ); @@ -2507,7 +2500,7 @@ public function testSelectWithFragmentedColumns(): void 1, 2, 3, - 4 + 4, ], $select ); @@ -2537,7 +2530,7 @@ public function testSelectWithFragmentedColumns(): void 1, 2, 3, - 4 + 4, ], $select ); diff --git a/tests/Database/StatementTest.php b/tests/Database/StatementTest.php index 982a39c5..f5adc19c 100644 --- a/tests/Database/StatementTest.php +++ b/tests/Database/StatementTest.php @@ -51,8 +51,8 @@ public function fillData(Table $table = null): void for ($i = 0; $i < 10; $i++) { $table->insertOne( [ - 'name' => md5((string)$i), - 'value' => $i * 10 + 'name' => md5((string)$i), + 'value' => $i * 10, ] ); } @@ -241,7 +241,7 @@ public function testToArray(): void $this->assertEquals( [ - ['id' => 1, 'name' => md5('0'), 'value' => 0] + ['id' => 1, 'name' => md5('0'), 'value' => 0], ], $result->fetchAll() ); @@ -254,7 +254,7 @@ public function testToObj(): void $result = $table->limit(1)->fetchAll(StatementInterface::FETCH_OBJ); - $this->assertTrue(is_object($result[0])); + $this->assertIsObject($result[0]); } public function testClose(): void diff --git a/tests/Database/TableTest.php b/tests/Database/TableTest.php index fc2ca66b..e623153b 100644 --- a/tests/Database/TableTest.php +++ b/tests/Database/TableTest.php @@ -169,9 +169,9 @@ public function testGetColumns(): void $this->assertSame( [ - 'id' => 'primary', - 'name' => 'text', - 'value' => 'integer' + 'id' => 'primary', + 'name' => 'text', + 'value' => 'integer', ], $columns ); @@ -185,8 +185,8 @@ public function testInsertOneRow(): void $id = $table->insertOne( [ - 'name' => 'Anton', - 'value' => 10 + 'name' => 'Anton', + 'value' => 10, ] ); @@ -197,7 +197,7 @@ public function testInsertOneRow(): void $this->assertEquals( [ - ['id' => 1, 'name' => 'Anton', 'value' => 10] + ['id' => 1, 'name' => 'Anton', 'value' => 10], ], $table->fetchAll() ); @@ -210,8 +210,8 @@ public function testInsertOneRowAfterAnother(): void $id = $table->insertOne( [ - 'name' => 'Anton', - 'value' => 10 + 'name' => 'Anton', + 'value' => 10, ] ); @@ -220,8 +220,8 @@ public function testInsertOneRowAfterAnother(): void $id = $table->insertOne( [ - 'name' => 'John', - 'value' => 20 + 'name' => 'John', + 'value' => 20, ] ); @@ -250,7 +250,7 @@ public function testInsertMultiple(): void ['Anton', 10], ['John', 20], ['Bob', 30], - ['Charlie', 40] + ['Charlie', 40], ] ); @@ -278,7 +278,7 @@ public function testAggregationByPass(): void ['Anton', 10], ['John', 20], ['Bob', 30], - ['Charlie', 40] + ['Charlie', 40], ] ); @@ -297,7 +297,7 @@ public function testAggregationMinByPass(): void ['Anton', 10], ['John', 20], ['Bob', 30], - ['Charlie', 40] + ['Charlie', 40], ] ); @@ -316,7 +316,7 @@ public function testAggregationMaxByPass(): void ['Anton', 10], ['John', 20], ['Bob', 30], - ['Charlie', 40] + ['Charlie', 40], ] ); @@ -335,7 +335,7 @@ public function testAggregationAvgByPass(): void ['Anton', 10], ['John', 20], ['Bob', 30], - ['Charlie', 40] + ['Charlie', 40], ] ); @@ -354,7 +354,7 @@ public function testAggregationAvgByPassFloat(): void ['Anton', 10], ['John', 20], ['Bob', 15], - ['Charlie', 10] + ['Charlie', 10], ] ); @@ -373,7 +373,7 @@ public function testDeleteWithWhere(): void ['Anton', 10], ['John', 20], ['Bob', 15], - ['Charlie', 10] + ['Charlie', 10], ] ); @@ -393,7 +393,7 @@ public function testUpdateWithWhere(): void ['Anton', 10], ['John', 20], ['Bob', 15], - ['Charlie', 10] + ['Charlie', 10], ] ); @@ -413,7 +413,7 @@ public function testUpdateWithFragment(): void ['Anton', 10], ['John', 20], ['Bob', 15], - ['Charlie', 10] + ['Charlie', 10], ] ); @@ -437,7 +437,7 @@ public function testTruncate(): void ['Anton', 10], ['John', 20], ['Bob', 15], - ['Charlie', 10] + ['Charlie', 10], ] ); @@ -457,7 +457,7 @@ public function testCountID(): void ['Anton', 10], ['John', 20], ['Bob', 15], - ['Charlie', 10] + ['Charlie', 10], ] ); @@ -475,7 +475,7 @@ public function testCountDistinct(): void ['Anton', 10], ['John', 20], ['Bob', 15], - ['Charlie', 10] + ['Charlie', 10], ] ); diff --git a/tests/Database/Tokens/DeleteQueryTest.php b/tests/Database/Tokens/DeleteQueryTest.php index ac336aa0..3f1de3dd 100644 --- a/tests/Database/Tokens/DeleteQueryTest.php +++ b/tests/Database/Tokens/DeleteQueryTest.php @@ -37,13 +37,13 @@ public function testBuildQuery(): void 'where' => [ [ 'AND', - ['name', '=', new Parameter('Antony')] + ['name', '=', new Parameter('Antony')], ], [ 'OR', - ['id', '>', new Parameter(1)] + ['id', '>', new Parameter(1)], ], - ] + ], ], $delete->getTokens() ); diff --git a/tests/Database/Tokens/InsertQueryTest.php b/tests/Database/Tokens/InsertQueryTest.php index bc67edc3..d4f6ab47 100644 --- a/tests/Database/Tokens/InsertQueryTest.php +++ b/tests/Database/Tokens/InsertQueryTest.php @@ -33,9 +33,9 @@ public function testBuildQuery(): void $this->assertEquals( [ - 'table' => 'table', + 'table' => 'table', 'columns' => ['name', 'value'], - 'values' => [new Parameter(['Antony', 1])] + 'values' => [new Parameter(['Antony', 1])], ], $insert->getTokens() ); diff --git a/tests/Database/Tokens/SelectQueryTest.php b/tests/Database/Tokens/SelectQueryTest.php index de5d28fa..bc36383c 100644 --- a/tests/Database/Tokens/SelectQueryTest.php +++ b/tests/Database/Tokens/SelectQueryTest.php @@ -35,11 +35,11 @@ public function testBuildQuery(): void $this->assertEquals( [ 'forUpdate' => false, - 'from' => ['table'], - 'join' => [], - 'columns' => ['name', 'value'], - 'distinct' => false, - 'where' => [ + 'from' => ['table'], + 'join' => [], + 'columns' => ['name', 'value'], + 'distinct' => false, + 'where' => [ [ 'AND', ['name', '=', new Parameter('Antony')], @@ -49,12 +49,12 @@ public function testBuildQuery(): void ['id', '>', new Parameter(1)], ], ], - 'having' => [], - 'groupBy' => [], - 'orderBy' => [], - 'limit' => null, - 'offset' => null, - 'union' => [], + 'having' => [], + 'groupBy' => [], + 'orderBy' => [], + 'limit' => null, + 'offset' => null, + 'union' => [], ], $select->getTokens() ); diff --git a/tests/Database/Tokens/UpdateQueryTest.php b/tests/Database/Tokens/UpdateQueryTest.php index cd3676be..41f980e6 100644 --- a/tests/Database/Tokens/UpdateQueryTest.php +++ b/tests/Database/Tokens/UpdateQueryTest.php @@ -34,20 +34,20 @@ public function testBuildQuery(): void $this->assertEquals( [ - 'table' => 'table', + 'table' => 'table', 'values' => [ - 'name' => 'John' + 'name' => 'John', ], - 'where' => [ + 'where' => [ [ 'AND', - ['name', '=', new Parameter('Antony')] + ['name', '=', new Parameter('Antony')], ], [ 'OR', - ['id', '>', new Parameter(1)] + ['id', '>', new Parameter(1)], ], - ] + ], ], $delete->getTokens() ); diff --git a/tests/Database/Traits/TableAssertions.php b/tests/Database/Traits/TableAssertions.php index f3e95e2b..47b75aa8 100644 --- a/tests/Database/Traits/TableAssertions.php +++ b/tests/Database/Traits/TableAssertions.php @@ -15,7 +15,6 @@ use Cycle\Database\Schema\AbstractForeignKey; use Cycle\Database\Schema\AbstractIndex; use Cycle\Database\Schema\AbstractTable; -use Cycle\Database\Schema\State; trait TableAssertions { diff --git a/tests/Database/UpdateQueryTest.php b/tests/Database/UpdateQueryTest.php index 8c9fe4dd..69caa601 100644 --- a/tests/Database/UpdateQueryTest.php +++ b/tests/Database/UpdateQueryTest.php @@ -73,7 +73,7 @@ public function testUpdateWithWhere(): void $this->assertSameParameters( [ 'Anton', - 1 + 1, ], $update ); @@ -88,13 +88,13 @@ public function testUpdate(): void $lastID = $this->database->insert('demo')->values( [ - 'value' => 'abc' + 'value' => 'abc', ] )->run(); $updated = $this->database->update('demo')->values( [ - 'value' => 'cde' + 'value' => 'cde', ] )->where('id', $lastID)->run(); @@ -119,7 +119,7 @@ public function testUpdateToNotNull(): void $lastID = $this->database->insert('demo')->values( [ - 'value' => null + 'value' => null, ] )->run(); @@ -134,7 +134,7 @@ public function testUpdateToNotNull(): void $updated = $this->database->update('demo')->values( [ - 'value' => 'abc' + 'value' => 'abc', ] )->where('id', $lastID)->run(); @@ -159,13 +159,13 @@ public function testUpdateToNull(): void $lastID = $this->database->insert('demo')->values( [ - 'value' => 'abc' + 'value' => 'abc', ] )->run(); $updated = $this->database->update('demo')->values( [ - 'value' => null + 'value' => null, ] )->where('id', $lastID)->run(); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 0c96ea3e..5d56d1e0 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -21,40 +21,40 @@ require dirname(__DIR__) . '/vendor/autoload.php'; $drivers = [ - 'sqlite' => [ - 'driver' => Database\Driver\SQLite\SQLiteDriver::class, - 'conn' => 'sqlite::memory:', - 'user' => 'sqlite', - 'pass' => '', - 'queryCache' => 100 + 'sqlite' => [ + 'driver' => Database\Driver\SQLite\SQLiteDriver::class, + 'conn' => 'sqlite::memory:', + 'user' => 'sqlite', + 'pass' => '', + 'queryCache' => 100, ], - 'mysql' => [ - 'driver' => Database\Driver\MySQL\MySQLDriver::class, - 'conn' => 'mysql:host=127.0.0.1:13306;dbname=spiral', - 'user' => 'root', - 'pass' => 'root', - 'queryCache' => 100 + 'mysql' => [ + 'driver' => Database\Driver\MySQL\MySQLDriver::class, + 'conn' => 'mysql:host=127.0.0.1:13306;dbname=spiral', + 'user' => 'root', + 'pass' => 'root', + 'queryCache' => 100, ], - 'postgres' => [ - 'driver' => Database\Driver\Postgres\PostgresDriver::class, - 'conn' => 'pgsql:host=127.0.0.1;port=15432;dbname=spiral', - 'user' => 'postgres', - 'pass' => 'postgres', - 'queryCache' => 100 + 'postgres' => [ + 'driver' => Database\Driver\Postgres\PostgresDriver::class, + 'conn' => 'pgsql:host=127.0.0.1;port=15432;dbname=spiral', + 'user' => 'postgres', + 'pass' => 'postgres', + 'queryCache' => 100, ], 'sqlserver' => [ - 'driver' => Database\Driver\SQLServer\SQLServerDriver::class, - 'conn' => 'sqlsrv:Server=127.0.0.1,11433;Database=tempdb', - 'user' => 'SA', - 'pass' => 'SSpaSS__1', - 'queryCache' => 100 + 'driver' => Database\Driver\SQLServer\SQLServerDriver::class, + 'conn' => 'sqlsrv:Server=127.0.0.1,11433;Database=tempdb', + 'user' => 'SA', + 'pass' => 'SSpaSS__1', + 'queryCache' => 100, ], ]; $db = getenv('DB') ?: null; Database\Tests\BaseTest::$config = [ - 'debug' => false, - ] + ( + 'debug' => false, +] + ( $db === null ? $drivers : array_intersect_key($drivers, array_flip((array)$db)) diff --git a/tests/generate.php b/tests/generate.php index a4cf47e7..0a836b5e 100644 --- a/tests/generate.php +++ b/tests/generate.php @@ -20,22 +20,22 @@ require dirname(__DIR__) . '/vendor/autoload.php'; $databases = [ - 'sqlite' => [ + 'sqlite' => [ 'namespace' => 'Cycle\Database\Tests\Driver\SQLite', - 'directory' => __DIR__ . '/Database/Driver/SQLite/' + 'directory' => __DIR__ . '/Database/Driver/SQLite/', ], - 'mysql' => [ + 'mysql' => [ 'namespace' => 'Cycle\Database\Tests\Driver\MySQL', - 'directory' => __DIR__ . '/Database/Driver/MySQL/' + 'directory' => __DIR__ . '/Database/Driver/MySQL/', ], - 'postgres' => [ + 'postgres' => [ 'namespace' => 'Cycle\Database\Tests\Driver\Postgres', - 'directory' => __DIR__ . '/Database/Driver/Postgres/' + 'directory' => __DIR__ . '/Database/Driver/Postgres/', ], 'sqlserver' => [ 'namespace' => 'Cycle\Database\Tests\Driver\SQLServer', - 'directory' => __DIR__ . '/Database/Driver/SQLServer/' - ] + 'directory' => __DIR__ . '/Database/Driver/SQLServer/', + ], ]; echo "Generating test classes for all database types...\n";