diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..f02a64bf --- /dev/null +++ b/.editorconfig @@ -0,0 +1,20 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.yml] +indent_style = space +indent_size = 2 + +[*.json] +indent_style = space +indent_size = 4 diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 00000000..24f3954e --- /dev/null +++ b/.styleci.yml @@ -0,0 +1,75 @@ +preset: psr12 +risky: true + +version: 7 + +enabled: + - alpha_ordered_traits + - array_indentation + - array_push + - combine_consecutive_issets + - combine_consecutive_unsets + - combine_nested_dirname + - declare_strict_types + - dir_constant + - fully_qualified_strict_types + - function_to_constant + - hash_to_slash_comment + - is_null + - logical_operators + - magic_constant_casing + - magic_method_casing + - method_separation + - modernize_types_casting + - native_function_casing + - native_function_type_declaration_casing + - no_alias_functions + - no_empty_comment + - no_empty_phpdoc + - no_empty_statement + - no_extra_block_blank_lines + - no_short_bool_cast + - no_superfluous_elseif + - no_unneeded_control_parentheses + - no_unneeded_curly_braces + - no_unneeded_final_method + - no_unset_cast + - no_unused_imports + - no_unused_lambda_imports + - no_useless_else + - no_useless_return + - normalize_index_brace + - php_unit_dedicate_assert + - php_unit_dedicate_assert_internal_type + - php_unit_expectation + - php_unit_mock + - php_unit_mock_short_will_return + - php_unit_namespaced + - php_unit_no_expectation_annotation + - phpdoc_no_empty_return + - phpdoc_no_useless_inheritdoc + - phpdoc_order + - phpdoc_property + - phpdoc_scalar + - phpdoc_separation + - phpdoc_singular_inheritdoc + - phpdoc_trim + - phpdoc_trim_consecutive_blank_line_separation + - phpdoc_type_to_var + - phpdoc_types + - phpdoc_types_order + - print_to_echo + - regular_callable_call + - return_assignment + - self_accessor + - self_static_accessor + - set_type_to_cast + - short_array_syntax + - short_list_syntax + - simplified_if_return + - single_quote + - standardize_not_equals + - ternary_to_null_coalescing + - trailing_comma_in_multiline_array + - unalign_double_arrow + - unalign_equals diff --git a/LICENSE b/LICENSE index be7d3b94..586cdb02 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2020 Spiral Scout +Copyright (c) 2021 Spiral Scout Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/composer.json b/composer.json index 6eaabea9..907e2e20 100644 --- a/composer.json +++ b/composer.json @@ -1,36 +1,60 @@ { - "name": "cycle/database", - "type": "library", - "description": "DBAL, schema introspection, migration and pagination", - "license": "MIT", - "authors": [ - { - "name": "Anton Titov / Wolfy-J", - "email": "wolfy.jd@gmail.com" - } - ], - "require": { - "php": ">=7.2", - "ext-pdo": "*", - "spiral/core": "^2.7", - "spiral/logger": "^2.7", - "spiral/pagination": "^2.7" - }, - "require-dev": { - "phpunit/phpunit": "~8.0", - "mockery/mockery": "^1.1", - "spiral/dumper": "^2.7", - "spiral/code-style": "^1.0", - "spiral/tokenizer": "^2.7" - }, - "autoload": { - "psr-4": { - "Cycle\\Database\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "Cycle\\Database\\Tests\\": "tests/Database/" - } - } + "name": "cycle/database", + "type": "library", + "description": "DBAL, schema introspection, migration and pagination", + "license": "MIT", + "authors": [ + { + "name": "Anton Titov / Wolfy-J", + "email": "wolfy.jd@gmail.com" + } + ], + "replace": { + "spiral/database": "^2.0" + }, + "require": { + "php": ">=7.2", + "ext-pdo": "*", + "spiral/core": "^2.8", + "spiral/logger": "^2.8", + "spiral/pagination": "^2.8" + }, + "autoload": { + "files": [ + "src/polyfill.php" + ], + "psr-4": { + "Cycle\\Database\\": "src" + } + }, + "require-dev": { + "vimeo/psalm": "^4.10", + "phpunit/phpunit": "^8.5|^9.0", + "mockery/mockery": "^1.3", + "spiral/dumper": "^2.8", + "spiral/code-style": "^1.0", + "spiral/tokenizer": "^2.8" + }, + "autoload-dev": { + "psr-4": { + "Cycle\\Database\\Tests\\": "tests/Database" + } + }, + "scripts": { + "test": [ + "phpcs --standard=phpcs.xml", + "psalm --no-cache", + "phpunit" + ] + }, + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "config": { + "sort-packages": true + }, + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 00000000..a81e1731 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ./src + diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 00000000..b82c72f3 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + diff --git a/resources/.phpstorm.meta.php b/resources/.phpstorm.meta.php new file mode 100644 index 00000000..55f0c22e --- /dev/null +++ b/resources/.phpstorm.meta.php @@ -0,0 +1,754 @@ +select(), stupid bug. - $columns = $columns[0]; + $arguments = $arguments[0]; } return $this->getDriver(self::READ) ->getQueryBuilder() - ->selectQuery($this->prefix, [], $columns); + ->selectQuery($this->prefix, [], $arguments); } /** diff --git a/src/DatabaseInterface.php b/src/DatabaseInterface.php index 2789d768..42fcd9d6 100644 --- a/src/DatabaseInterface.php +++ b/src/DatabaseInterface.php @@ -1,10 +1,10 @@ config->getDefaultDatabase(); } - //Spiral support ability to link multiple virtual databases together using aliases + // Cycle support ability to link multiple virtual databases together + // using aliases. $database = $this->config->resolveAlias($database); if (isset($this->databases[$database])) { diff --git a/src/DatabaseProviderInterface.php b/src/DatabaseProviderInterface.php index 2492d243..ada66cbc 100644 --- a/src/DatabaseProviderInterface.php +++ b/src/DatabaseProviderInterface.php @@ -1,10 +1,10 @@ driver->query( $query, - [$this->driver->getSource(), $name] + [$this->driver->getSource(), $table] )->fetchColumn(); } diff --git a/src/Driver/MySQL/Schema/MySQLColumn.php b/src/Driver/MySQL/Schema/MySQLColumn.php index a8f20884..596f38b8 100644 --- a/src/Driver/MySQL/Schema/MySQLColumn.php +++ b/src/Driver/MySQL/Schema/MySQLColumn.php @@ -1,10 +1,10 @@ exec("SET NAMES 'UTF-8'"); diff --git a/src/Driver/Postgres/PostgresHandler.php b/src/Driver/Postgres/PostgresHandler.php index 0422f499..6c096fbf 100644 --- a/src/Driver/Postgres/PostgresHandler.php +++ b/src/Driver/Postgres/PostgresHandler.php @@ -1,10 +1,10 @@ type = $schema['typname']; /** - * Attention, this is not default spiral enum type emulated via CHECK. This is real - * Postgres enum type. + * Attention, this is not default enum type emulated via CHECK. + * This is real Postgres enum type. */ self::resolveEnum($driver, $column); } diff --git a/src/Driver/Postgres/Schema/PostgresForeignKey.php b/src/Driver/Postgres/Schema/PostgresForeignKey.php index 6ff46bab..9fd24f3a 100644 --- a/src/Driver/Postgres/Schema/PostgresForeignKey.php +++ b/src/Driver/Postgres/Schema/PostgresForeignKey.php @@ -1,10 +1,10 @@ bindParam( $index, $parameter, diff --git a/src/Driver/SQLServer/SQLServerHandler.php b/src/Driver/SQLServer/SQLServerHandler.php index cbe97bca..61bac289 100644 --- a/src/Driver/SQLServer/SQLServerHandler.php +++ b/src/Driver/SQLServer/SQLServerHandler.php @@ -1,10 +1,10 @@ driver->query($query, [$name])->fetchColumn(); + return (bool)$this->driver->query($query, [$table])->fetchColumn(); } /** diff --git a/src/Driver/SQLServer/Schema/SQLServerColumn.php b/src/Driver/SQLServer/Schema/SQLServerColumn.php index 08112510..ecf86e0f 100644 --- a/src/Driver/SQLServer/Schema/SQLServerColumn.php +++ b/src/Driver/SQLServer/Schema/SQLServerColumn.php @@ -1,10 +1,10 @@ $schema) { + foreach ($indexes as $_ => $schema) { //Once all columns are aggregated we can finally create an index $result[] = SQLServerIndex::createInstance($this->getName(), $schema); } @@ -116,7 +116,7 @@ protected function fetchReferences(): array $result = []; foreach ($fks as $schema) { - $result[] = SQlServerForeignKey::createInstance( + $result[] = SQLServerForeignKey::createInstance( $this->getName(), $this->getPrefix(), $schema @@ -171,6 +171,6 @@ protected function createIndex(string $name): AbstractIndex */ protected function createForeign(string $name): AbstractForeignKey { - return new SQlServerForeignKey($this->getName(), $this->getPrefix(), $name); + return new SQLServerForeignKey($this->getName(), $this->getPrefix(), $name); } } diff --git a/src/Driver/SQLite/SQLiteCompiler.php b/src/Driver/SQLite/SQLiteCompiler.php index cf344969..882d3b80 100644 --- a/src/Driver/SQLite/SQLiteCompiler.php +++ b/src/Driver/SQLite/SQLiteCompiler.php @@ -1,10 +1,10 @@ fetchColumn(); /* - * There is not really many ways to get extra information about column in SQLite, let's parse - * table schema. As mention, spiral SQLite schema reader will support fully only tables created - * by spiral as we expecting every column definition be on new line. - */ + * There is not really many ways to get extra information about column + * in SQLite, let's parse table schema. As mention, Cycle SQLite + * schema reader will support fully only tables created by Cycle as we + * expecting every column definition be on new line. + */ $definition = explode("\n", $definition); $result = []; diff --git a/src/Driver/Statement.php b/src/Driver/Statement.php index deabfb65..319ead4b 100644 --- a/src/Driver/Statement.php +++ b/src/Driver/Statement.php @@ -1,10 +1,10 @@ current->getIndexes() as $name => $index) { + foreach ($this->current->getIndexes() as $_ => $index) { if (!$this->initial->hasIndex($index->getColumnsWithSort())) { $difference[] = $index; } @@ -155,7 +155,7 @@ public function addedIndexes(): array public function droppedIndexes(): array { $difference = []; - foreach ($this->initial->getIndexes() as $name => $index) { + foreach ($this->initial->getIndexes() as $_ => $index) { if (!$this->current->hasIndex($index->getColumnsWithSort())) { $difference[] = $index; } @@ -173,7 +173,7 @@ public function alteredIndexes(): array { $difference = []; - foreach ($this->current->getIndexes() as $name => $index) { + foreach ($this->current->getIndexes() as $_ => $index) { if (!$this->initial->hasIndex($index->getColumnsWithSort())) { //Added into schema continue; @@ -194,7 +194,7 @@ public function alteredIndexes(): array public function addedForeignKeys(): array { $difference = []; - foreach ($this->current->getForeignKeys() as $name => $foreignKey) { + foreach ($this->current->getForeignKeys() as $_ => $foreignKey) { if (!$this->initial->hasForeignKey($foreignKey->getColumns())) { $difference[] = $foreignKey; } @@ -209,7 +209,7 @@ public function addedForeignKeys(): array public function droppedForeignKeys(): array { $difference = []; - foreach ($this->initial->getForeignKeys() as $name => $foreignKey) { + foreach ($this->initial->getForeignKeys() as $_ => $foreignKey) { if (!$this->current->hasForeignKey($foreignKey->getColumns())) { $difference[] = $foreignKey; } @@ -227,7 +227,7 @@ public function alteredForeignKeys(): array { $difference = []; - foreach ($this->current->getForeignKeys() as $name => $foreignKey) { + foreach ($this->current->getForeignKeys() as $_ => $foreignKey) { if (!$this->initial->hasForeignKey($foreignKey->getColumns())) { //Added into schema continue; diff --git a/src/Schema/ComparatorInterface.php b/src/Schema/ComparatorInterface.php index e3be69ba..09e92f24 100644 --- a/src/Schema/ComparatorInterface.php +++ b/src/Schema/ComparatorInterface.php @@ -1,10 +1,10 @@ beginTransaction(null, false); } else { - /** @var DriverInterface $driver */ $driver->beginTransaction(null); } } @@ -192,7 +191,6 @@ protected function beginTransaction(): void protected function commitTransaction(): void { foreach ($this->drivers as $driver) { - /** @var DriverInterface $driver */ $driver->commitTransaction(); } } @@ -203,7 +201,6 @@ protected function commitTransaction(): void protected function rollbackTransaction(): void { foreach (array_reverse($this->drivers) as $driver) { - /** @var DriverInterface $driver */ $driver->rollbackTransaction(); } } diff --git a/src/Schema/State.php b/src/Schema/State.php index 1f760588..38067df3 100644 --- a/src/Schema/State.php +++ b/src/Schema/State.php @@ -1,10 +1,10 @@