From 5ff2cd0d13dec839ce74445851fe7f9a834c1283 Mon Sep 17 00:00:00 2001 From: Jan Tvrdik Date: Sat, 19 Dec 2020 14:49:48 +0100 Subject: [PATCH 01/12] remove most deprecated files --- composer.bridgeless.json | 2 +- composer.json | 2 +- src/deprecated/DbPhp.php | 32 ------------------ src/deprecated/MySqlNetteDbDriver.php | 27 --------------- src/deprecated/NetteDbSql.php | 47 --------------------------- src/deprecated/PgSqlNetteDbDriver.php | 27 --------------- src/deprecated/SimplePhp.php | 29 ----------------- 7 files changed, 2 insertions(+), 164 deletions(-) delete mode 100644 src/deprecated/DbPhp.php delete mode 100644 src/deprecated/MySqlNetteDbDriver.php delete mode 100644 src/deprecated/NetteDbSql.php delete mode 100644 src/deprecated/PgSqlNetteDbDriver.php delete mode 100644 src/deprecated/SimplePhp.php diff --git a/composer.bridgeless.json b/composer.bridgeless.json index 74aa559..4b7bffd 100644 --- a/composer.bridgeless.json +++ b/composer.bridgeless.json @@ -5,7 +5,7 @@ }, "autoload": { "psr-4": { "Nextras\\Migrations\\": "src/" }, - "classmap": ["src/exceptions.php", "src/deprecated"] + "classmap": ["src/exceptions.php"] }, "autoload-dev": { "classmap": ["tests/inc"] diff --git a/composer.json b/composer.json index 6969656..bcee90b 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ }, "autoload": { "psr-4": { "Nextras\\Migrations\\": "src/" }, - "classmap": ["src/exceptions.php", "src/deprecated"] + "classmap": ["src/exceptions.php"] }, "autoload-dev": { "classmap": ["tests/inc"] diff --git a/src/deprecated/DbPhp.php b/src/deprecated/DbPhp.php deleted file mode 100644 index c9d2e8f..0000000 --- a/src/deprecated/DbPhp.php +++ /dev/null @@ -1,32 +0,0 @@ - $context]); - } - - - public function getName() - { - return 'db.php'; - } - -} diff --git a/src/deprecated/MySqlNetteDbDriver.php b/src/deprecated/MySqlNetteDbDriver.php deleted file mode 100644 index f015332..0000000 --- a/src/deprecated/MySqlNetteDbDriver.php +++ /dev/null @@ -1,27 +0,0 @@ -getConnection()), $tableName); - } - -} diff --git a/src/deprecated/NetteDbSql.php b/src/deprecated/NetteDbSql.php deleted file mode 100644 index 016364f..0000000 --- a/src/deprecated/NetteDbSql.php +++ /dev/null @@ -1,47 +0,0 @@ -getConnection(); - $driver = $connection->getSupplementalDriver(); - $dbal = new NetteAdapter($connection); - - if ($driver instanceof Nette\Database\Drivers\PgSqlDriver) { - parent::__construct(new PgSqlDriver($dbal, 'migrations')); - - } elseif ($driver instanceof Nette\Database\Drivers\MySqlDriver) { - parent::__construct(new MySqlDriver($dbal, 'migrations')); - - } else { - throw new \LogicException(); - } - } - - - public function getName() - { - return 'sql'; - } - -} diff --git a/src/deprecated/PgSqlNetteDbDriver.php b/src/deprecated/PgSqlNetteDbDriver.php deleted file mode 100644 index 51d28f9..0000000 --- a/src/deprecated/PgSqlNetteDbDriver.php +++ /dev/null @@ -1,27 +0,0 @@ -getConnection()), $tableName, $schema); - } - -} diff --git a/src/deprecated/SimplePhp.php b/src/deprecated/SimplePhp.php deleted file mode 100644 index 5cdf1a0..0000000 --- a/src/deprecated/SimplePhp.php +++ /dev/null @@ -1,29 +0,0 @@ - Date: Sat, 20 Jan 2024 19:31:02 +0100 Subject: [PATCH 02/12] remove support for dibi 2.x --- src/Bridges/Dibi/Dibi2Adapter.php | 73 ------------------- src/Bridges/Dibi/DibiAdapter.php | 3 - src/Bridges/NetteDI/MigrationsExtension.php | 4 +- .../DependencyInjection/Configuration.php | 2 +- .../NextrasMigrationsExtension.php | 1 - tests/inc/IntegrationTestCase.php | 4 +- tests/matrix/dbal/dibi-2.0.sh | 5 -- 7 files changed, 3 insertions(+), 89 deletions(-) delete mode 100644 src/Bridges/Dibi/Dibi2Adapter.php delete mode 100644 tests/matrix/dbal/dibi-2.0.sh diff --git a/src/Bridges/Dibi/Dibi2Adapter.php b/src/Bridges/Dibi/Dibi2Adapter.php deleted file mode 100644 index ffccb06..0000000 --- a/src/Bridges/Dibi/Dibi2Adapter.php +++ /dev/null @@ -1,73 +0,0 @@ -conn = $dibi; - } - - - public function query($sql) - { - $result = $this->conn->nativeQuery($sql); - $result->setRowClass(NULL); - return $result->fetchAll(); - } - - - public function exec($sql) - { - return $this->conn->nativeQuery($sql); - } - - - public function escapeString($value) - { - return $this->conn->getDriver()->escape($value, dibi::TEXT); - } - - - public function escapeInt($value) - { - return (string) (int) $value; - } - - - public function escapeBool($value) - { - return $this->conn->getDriver()->escape($value, dibi::BOOL); - } - - - public function escapeDateTime(DateTime $value) - { - return $this->conn->getDriver()->escape($value, dibi::DATETIME); - } - - - public function escapeIdentifier($value) - { - return $this->conn->getDriver()->escape($value, dibi::IDENTIFIER); - } - -} diff --git a/src/Bridges/Dibi/DibiAdapter.php b/src/Bridges/Dibi/DibiAdapter.php index 8170954..364f56b 100644 --- a/src/Bridges/Dibi/DibiAdapter.php +++ b/src/Bridges/Dibi/DibiAdapter.php @@ -26,9 +26,6 @@ public function __construct($conn) if (version_compare(dibi::VERSION, '3.0.0', '>=')) { $this->innerAdapter = new Dibi3Adapter($conn); - } elseif (version_compare(dibi::VERSION, '2.0.0', '>=')) { - $this->innerAdapter = new Dibi2Adapter($conn); - } else { throw new LogicException('Unsupported dibi version'); } diff --git a/src/Bridges/NetteDI/MigrationsExtension.php b/src/Bridges/NetteDI/MigrationsExtension.php index 42874ba..8f3e917 100644 --- a/src/Bridges/NetteDI/MigrationsExtension.php +++ b/src/Bridges/NetteDI/MigrationsExtension.php @@ -40,7 +40,6 @@ class MigrationsExtension extends Nette\DI\CompilerExtension /** @var array */ protected $dbals = [ 'dibi' => 'Nextras\Migrations\Bridges\Dibi\DibiAdapter', - 'dibi2' => 'Nextras\Migrations\Bridges\Dibi\Dibi2Adapter', 'dibi3' => 'Nextras\Migrations\Bridges\Dibi\Dibi3Adapter', 'dibi4' => 'Nextras\Migrations\Bridges\Dibi\Dibi3Adapter', 'doctrine' => 'Nextras\Migrations\Bridges\DoctrineDbal\DoctrineAdapter', @@ -118,8 +117,7 @@ public function beforeCompile() continue; } - $dibiClassName = version_compare(\dibi::VERSION, '3.0.0', '<') ? 'DibiConnection' : 'Dibi\Connection'; - $conn = $builder->getByType($dibiClassName); + $conn = $builder->getByType('Dibi\Connection'); if (!$conn) { continue; } diff --git a/src/Bridges/SymfonyBundle/DependencyInjection/Configuration.php b/src/Bridges/SymfonyBundle/DependencyInjection/Configuration.php index 20120db..b1e7229 100644 --- a/src/Bridges/SymfonyBundle/DependencyInjection/Configuration.php +++ b/src/Bridges/SymfonyBundle/DependencyInjection/Configuration.php @@ -32,7 +32,7 @@ public function getConfigTreeBuilder() ->cannotBeEmpty() ->end() ->enumNode('dbal') - ->values(['dibi', 'dibi2', 'dibi3', 'dibi4', 'doctrine', 'nette', 'nextras']) + ->values(['dibi', 'dibi3', 'dibi4', 'doctrine', 'nette', 'nextras']) ->defaultValue('doctrine') ->cannotBeEmpty() ->end() diff --git a/src/Bridges/SymfonyBundle/DependencyInjection/NextrasMigrationsExtension.php b/src/Bridges/SymfonyBundle/DependencyInjection/NextrasMigrationsExtension.php index 7621c0a..eded90b 100644 --- a/src/Bridges/SymfonyBundle/DependencyInjection/NextrasMigrationsExtension.php +++ b/src/Bridges/SymfonyBundle/DependencyInjection/NextrasMigrationsExtension.php @@ -19,7 +19,6 @@ class NextrasMigrationsExtension extends Extension /** @var array */ protected $dbals = [ 'dibi' => 'Nextras\Migrations\Bridges\Dibi\DibiAdapter', - 'dibi2' => 'Nextras\Migrations\Bridges\Dibi\Dibi2Adapter', 'dibi3' => 'Nextras\Migrations\Bridges\Dibi\Dibi3Adapter', 'dibi4' => 'Nextras\Migrations\Bridges\Dibi\Dibi3Adapter', 'doctrine' => 'Nextras\Migrations\Bridges\DoctrineDbal\DoctrineAdapter', diff --git a/tests/inc/IntegrationTestCase.php b/tests/inc/IntegrationTestCase.php index 59f058e..cf03f3f 100644 --- a/tests/inc/IntegrationTestCase.php +++ b/tests/inc/IntegrationTestCase.php @@ -3,7 +3,6 @@ namespace NextrasTests\Migrations; use Dibi; -use DibiConnection; use Doctrine; use Nette; use Nextras; @@ -131,8 +130,7 @@ protected function createDbal($options) 'pgsql' => 'postgre', ]; - $dibiConnectionClass = class_exists('Dibi\Connection') ? 'Dibi\Connection' : 'DibiConnection'; - return new DibiAdapter(new $dibiConnectionClass([ + return new DibiAdapter(new Dibi\Connection([ 'host' => $options['host'], 'username' => $options['username'], 'password' => $options['password'], diff --git a/tests/matrix/dbal/dibi-2.0.sh b/tests/matrix/dbal/dibi-2.0.sh deleted file mode 100644 index 34bad8c..0000000 --- a/tests/matrix/dbal/dibi-2.0.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -PHP_VERSION_MIN="50400" -PHP_VERSION_MAX="70199" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE dibi/dibi:~2.3" -DBAL="dibi" From 9297f2895d65bbdcf19db5ea75b7dd92d0e27027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Tvrd=C3=ADk?= Date: Sat, 20 Jan 2024 19:32:29 +0100 Subject: [PATCH 03/12] remove support for nette/di 2.3 --- composer.json | 2 +- tests/matrix/nette-di/nette-2.3-php-5.4.sh | 10 ---------- tests/matrix/nette-di/nette-2.3-php-5.5-to-7.1.sh | 11 ----------- 3 files changed, 1 insertion(+), 22 deletions(-) delete mode 100644 tests/matrix/nette-di/nette-2.3-php-5.4.sh delete mode 100644 tests/matrix/nette-di/nette-2.3-php-5.5-to-7.1.sh diff --git a/composer.json b/composer.json index bcee90b..0969e8b 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "doctrine/orm": "~2.5", "mockery/mockery": "~0.9 | ~1.0", "nette/database": "~2.2", - "nette/di": "~2.3.12 | ~2.4", + "nette/di": "~2.4", "nette/tester": "~1.7 | ~2.0", "nette/utils": "~2.3", "nextras/dbal": "~1.0 | ~2.0 | ~3.0 | ~4.0 | ~5.0@dev", diff --git a/tests/matrix/nette-di/nette-2.3-php-5.4.sh b/tests/matrix/nette-di/nette-2.3-php-5.4.sh deleted file mode 100644 index 61d5bce..0000000 --- a/tests/matrix/nette-di/nette-2.3-php-5.4.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -PHP_VERSION_MIN="50400" -PHP_VERSION_MAX="50499" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE nette/di:~2.3.12" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE nette/utils:~2.3.0" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE dibi/dibi:~3.0" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE doctrine/dbal:~2.5" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE doctrine/orm:~2.0" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE nextras/dbal:~1.0" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE symfony/console:~2.8" diff --git a/tests/matrix/nette-di/nette-2.3-php-5.5-to-7.1.sh b/tests/matrix/nette-di/nette-2.3-php-5.5-to-7.1.sh deleted file mode 100644 index 3c09cda..0000000 --- a/tests/matrix/nette-di/nette-2.3-php-5.5-to-7.1.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -PHP_VERSION_MIN="50500" -PHP_VERSION_MAX="70199" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE nette/di:~2.3.12" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE nette/utils:~2.3.0" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE dibi/dibi:~3.0" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE doctrine/dbal:~2.5" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE doctrine/orm:~2.0" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE doctrine/cache:~1.6" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE nextras/dbal:~2.0" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE symfony/console:~3.0" From 5139d54801bd82a53015bd67443d6a9211d69ded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Tvrd=C3=ADk?= Date: Sat, 20 Jan 2024 23:32:30 +0100 Subject: [PATCH 04/12] remove support for nette/database 2.2 --- composer.json | 2 +- tests/matrix/dbal/nette-2.0-php-5.4-to-7.1.sh | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) delete mode 100644 tests/matrix/dbal/nette-2.0-php-5.4-to-7.1.sh diff --git a/composer.json b/composer.json index 0969e8b..fb39637 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "doctrine/dbal": "~2.5 | ~3.0", "doctrine/orm": "~2.5", "mockery/mockery": "~0.9 | ~1.0", - "nette/database": "~2.2", + "nette/database": "~2.4", "nette/di": "~2.4", "nette/tester": "~1.7 | ~2.0", "nette/utils": "~2.3", diff --git a/tests/matrix/dbal/nette-2.0-php-5.4-to-7.1.sh b/tests/matrix/dbal/nette-2.0-php-5.4-to-7.1.sh deleted file mode 100644 index e27c390..0000000 --- a/tests/matrix/dbal/nette-2.0-php-5.4-to-7.1.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash -PHP_VERSION_MIN="50400" -PHP_VERSION_MAX="70199" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE nette/database:~2.2" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE nette/caching:~2.2" -DBAL="nette" From 227e055bc431c9b0399111745d3471e77327ffb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Tvrd=C3=ADk?= Date: Sat, 20 Jan 2024 19:34:54 +0100 Subject: [PATCH 05/12] require PHP 7.1+ --- .github/workflows/qa.yaml | 2 +- composer.json | 2 +- tests/matrix/nette-di/nette-2.4-php-5.6-to-7.0.sh | 10 ---------- 3 files changed, 2 insertions(+), 12 deletions(-) delete mode 100644 tests/matrix/nette-di/nette-2.4-php-5.6-to-7.0.sh diff --git a/.github/workflows/qa.yaml b/.github/workflows/qa.yaml index ca41dd2..642215a 100644 --- a/.github/workflows/qa.yaml +++ b/.github/workflows/qa.yaml @@ -16,7 +16,7 @@ jobs: strategy: fail-fast: false matrix: - php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] + php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] name: PHP ${{ matrix.php }} diff --git a/composer.json b/composer.json index fb39637..3a09369 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "library", "license": "BSD-3-Clause", "require": { - "php": ">=5.4" + "php": ">=7.1" }, "require-dev": { "dibi/dibi": "~3.0 | ~4.0", diff --git a/tests/matrix/nette-di/nette-2.4-php-5.6-to-7.0.sh b/tests/matrix/nette-di/nette-2.4-php-5.6-to-7.0.sh deleted file mode 100644 index 4cf2d65..0000000 --- a/tests/matrix/nette-di/nette-2.4-php-5.6-to-7.0.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -PHP_VERSION_MIN="50600" -PHP_VERSION_MAX="70099" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE nette/di:~2.4.1" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE nette/utils:~2.4.0" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE dibi/dibi:~3.0" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE doctrine/dbal:~2.5" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE doctrine/orm:~2.0" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE nextras/dbal:~2.0" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE symfony/console:~3.0" From e65c5342173fca24f10e4974fbc5a66d4ec729ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Tvrd=C3=ADk?= Date: Sat, 20 Jan 2024 19:35:09 +0100 Subject: [PATCH 06/12] update dev dependencies --- .github/workflows/qa.yaml | 2 -- composer.bridgeless.json | 4 ++-- composer.json | 12 ++++++------ tests/php-unix.sample.ini | 7 ------- tests/php-win.sample.ini | 7 ------- tests/run-integration.sh | 3 +-- tests/run-unit.sh | 3 +-- 7 files changed, 10 insertions(+), 28 deletions(-) delete mode 100644 tests/php-unix.sample.ini delete mode 100644 tests/php-win.sample.ini diff --git a/.github/workflows/qa.yaml b/.github/workflows/qa.yaml index 642215a..74a9d8e 100644 --- a/.github/workflows/qa.yaml +++ b/.github/workflows/qa.yaml @@ -59,8 +59,6 @@ jobs: - name: Prepare Env run: | - PHP_DIR=$(php -r 'echo dirname(php_ini_loaded_file());') - cat $PHP_DIR/php.ini $PHP_DIR/conf.d/*.ini > ./tests/php.ini cp ./tests/drivers.sample.ini ./tests/drivers.ini composer install --no-interaction --no-progress diff --git a/composer.bridgeless.json b/composer.bridgeless.json index 4b7bffd..613f356 100644 --- a/composer.bridgeless.json +++ b/composer.bridgeless.json @@ -1,7 +1,7 @@ { "require-dev": { - "nette/tester": "~1.7", - "mockery/mockery": "~0.9" + "nette/tester": "~2.3", + "mockery/mockery": "~1.3.0" }, "autoload": { "psr-4": { "Nextras\\Migrations\\": "src/" }, diff --git a/composer.json b/composer.json index 3a09369..796e449 100644 --- a/composer.json +++ b/composer.json @@ -11,18 +11,18 @@ "doctrine/cache": "~1.5", "doctrine/dbal": "~2.5 | ~3.0", "doctrine/orm": "~2.5", - "mockery/mockery": "~0.9 | ~1.0", - "nette/database": "~2.4", - "nette/di": "~2.4", - "nette/tester": "~1.7 | ~2.0", - "nette/utils": "~2.3", + "mockery/mockery": "~1.3", + "nette/database": "~2.4 | ~3.0", + "nette/di": "~2.4.10 | ~3.0", + "nette/tester": "~2.3", + "nette/utils": "~2.3 | ~3.0 | ~4.0", "nextras/dbal": "~1.0 | ~2.0 | ~3.0 | ~4.0 | ~5.0@dev", "symfony/config": "~2.6 | ~3.0 | ~4.0 | ~5.0 | ~6.0", "symfony/console": "~2.6 | ~3.0 | ~4.0 | ~5.0 | ~6.0", "symfony/dependency-injection": "~2.6 | ~3.0 | ~4.0 | ~5.0 | ~6.0", "symfony/framework-bundle": "~2.6 | ~3.0 | ~4.0 | ~5.0 | ~6.0", "symfony/http-kernel": "~2.6 | ~3.0 | ~4.0 | ~5.0 | ~6.0", - "tracy/tracy": "^2.2", + "tracy/tracy": "~2.6", "ext-openssl": "*" }, "suggest": { diff --git a/tests/php-unix.sample.ini b/tests/php-unix.sample.ini deleted file mode 100644 index 22d2851..0000000 --- a/tests/php-unix.sample.ini +++ /dev/null @@ -1,7 +0,0 @@ -[PHP] -; extension_dir = "./ext" -extension=php_mysqli.so -extension=php_pgsql.so -extension=php_openssl.so -extension=php_pdo_mysql.so -extension=php_pdo_pgsql.so diff --git a/tests/php-win.sample.ini b/tests/php-win.sample.ini deleted file mode 100644 index 62d0cfd..0000000 --- a/tests/php-win.sample.ini +++ /dev/null @@ -1,7 +0,0 @@ -[PHP] -extension_dir = "./ext" -extension=php_mysqli.dll -extension=php_pgsql.dll -extension=php_openssl.dll -extension=php_pdo_mysql.dll -extension=php_pdo_pgsql.dll diff --git a/tests/run-integration.sh b/tests/run-integration.sh index 5132e39..61b96c4 100755 --- a/tests/run-integration.sh +++ b/tests/run-integration.sh @@ -96,8 +96,7 @@ tester_run_integration_group() INTEGRATION_GROUP="$1" "$PROJECT_DIR/vendor/bin/tester" \ - -p php \ - -c "$PROJECT_DIR/tests/php.ini" \ + -C \ -o console \ "$PROJECT_DIR/tests/cases/integration/$INTEGRATION_GROUP" } diff --git a/tests/run-unit.sh b/tests/run-unit.sh index 2aed676..dc395ed 100755 --- a/tests/run-unit.sh +++ b/tests/run-unit.sh @@ -4,7 +4,6 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_DIR="$(dirname "$DIR")" "$PROJECT_DIR/vendor/bin/tester" \ - -p php \ - -c "$PROJECT_DIR/tests/php.ini" \ + -C \ -o console \ "$PROJECT_DIR/tests/cases/unit" From c79c251982516336e80c349849c5d0657d11f426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Tvrd=C3=ADk?= Date: Sat, 20 Jan 2024 23:38:17 +0100 Subject: [PATCH 07/12] update dev dependencies # Conflicts: # composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 796e449..83d53a7 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ }, "require-dev": { "dibi/dibi": "~3.0 | ~4.0", - "doctrine/cache": "~1.5", + "doctrine/cache": "~1.11 | ~2.0", "doctrine/dbal": "~2.5 | ~3.0", "doctrine/orm": "~2.5", "mockery/mockery": "~1.3", From 99be4a08556cc4386fd0ece7c67750662224e7ea Mon Sep 17 00:00:00 2001 From: Jan Tvrdik Date: Sun, 20 Dec 2020 16:43:36 +0100 Subject: [PATCH 08/12] update coding style --- src/Bridges/Dibi/Dibi3Adapter.php | 2 +- src/Bridges/DoctrineDbal/DoctrineAdapter.php | 1 - .../DoctrineOrm/StructureDiffGenerator.php | 14 +++---- src/Bridges/NetteDI/MigrationsExtension.php | 42 ++++++++++--------- src/Bridges/NetteDatabase/NetteAdapter.php | 1 - src/Bridges/NextrasDbal/NextrasAdapter.php | 1 - .../NextrasMigrationsExtension.php | 8 ++-- src/Bridges/SymfonyConsole/BaseCommand.php | 1 - .../SymfonyConsole/ContinueCommand.php | 1 - src/Bridges/SymfonyConsole/CreateCommand.php | 19 ++++----- src/Bridges/SymfonyConsole/ResetCommand.php | 2 +- src/Configurations/Configuration.php | 4 +- src/Configurations/DefaultConfiguration.php | 15 ++++--- src/Controllers/BaseController.php | 9 ++-- src/Controllers/ConsoleController.php | 12 +++--- src/Controllers/HttpController.php | 21 +++++----- src/Drivers/BaseDriver.php | 13 +++--- src/Drivers/MySqlDriver.php | 7 ++-- src/Drivers/PgSqlDriver.php | 15 ++++--- src/Engine/Finder.php | 17 ++++---- src/Engine/OrderResolver.php | 19 ++++----- src/Engine/Runner.php | 13 +++--- src/Entities/File.php | 1 - src/Entities/Group.php | 3 +- src/Entities/Migration.php | 1 - src/Extensions/PhpHandler.php | 5 +-- src/Extensions/SqlHandler.php | 3 +- src/IConfiguration.php | 1 - src/IDiffGenerator.php | 2 +- src/IDriver.php | 10 ++++- src/IExtensionHandler.php | 1 - src/IPrinter.php | 12 ++++-- src/Printers/Console.php | 12 +++--- src/Printers/DevNull.php | 1 + src/Printers/HtmlDump.php | 3 +- .../integration/dbal/Runner.FirstRun.phpt | 12 +++--- .../nette-di/MigrationsExtension.phpt | 6 +-- .../symfony-bundle/SymfonyBundleTest.phpt | 2 +- tests/cases/unit/BaseDriverTest.phpt | 2 +- tests/cases/unit/Finder.logicalName.phpt | 2 +- tests/cases/unit/OrderResolverTest.phpt | 40 +++++++++--------- tests/inc/IntegrationTestCase.php | 8 ++-- tests/inc/TestPrinter.php | 2 +- tests/inc/TestSymfonyKernel.php | 2 +- tests/inc/TestSymfonyKernel6.php | 2 +- 45 files changed, 180 insertions(+), 190 deletions(-) diff --git a/src/Bridges/Dibi/Dibi3Adapter.php b/src/Bridges/Dibi/Dibi3Adapter.php index 350a081..fa3fd0a 100644 --- a/src/Bridges/Dibi/Dibi3Adapter.php +++ b/src/Bridges/Dibi/Dibi3Adapter.php @@ -29,7 +29,7 @@ public function __construct(Dibi\Connection $dibi) public function query($sql) { $result = $this->conn->nativeQuery($sql); - $result->setRowClass(NULL); + $result->setRowClass(null); return $result->fetchAll(); } diff --git a/src/Bridges/DoctrineDbal/DoctrineAdapter.php b/src/Bridges/DoctrineDbal/DoctrineAdapter.php index 913a67a..fd7486c 100644 --- a/src/Bridges/DoctrineDbal/DoctrineAdapter.php +++ b/src/Bridges/DoctrineDbal/DoctrineAdapter.php @@ -70,5 +70,4 @@ public function escapeIdentifier($value) { return $this->conn->quoteIdentifier($value); } - } diff --git a/src/Bridges/DoctrineOrm/StructureDiffGenerator.php b/src/Bridges/DoctrineOrm/StructureDiffGenerator.php index d32e59b..2246c06 100644 --- a/src/Bridges/DoctrineOrm/StructureDiffGenerator.php +++ b/src/Bridges/DoctrineOrm/StructureDiffGenerator.php @@ -18,19 +18,18 @@ class StructureDiffGenerator implements IDiffGenerator { - /** @var EntityManagerInterface */ private $entityManager; - /** @var string|NULL absolute path to a file */ + /** @var string|null absolute path to a file */ private $ignoredQueriesFile; /** - * @param EntityManagerInterface $entityManager - * @param string|NULL $ignoredQueriesFile + * @param EntityManagerInterface $entityManager + * @param string|NULL $ignoredQueriesFile */ - public function __construct(EntityManagerInterface $entityManager, $ignoredQueriesFile = NULL) + public function __construct(EntityManagerInterface $entityManager, $ignoredQueriesFile = null) { $this->entityManager = $entityManager; $this->ignoredQueriesFile = $ignoredQueriesFile; @@ -70,7 +69,7 @@ protected function getUpdateQueries() $schemaTool = new SchemaTool($this->entityManager); $metadata = $this->entityManager->getMetadataFactory()->getAllMetadata(); - $queries = $schemaTool->getUpdateSchemaSql($metadata, TRUE); + $queries = $schemaTool->getUpdateSchemaSql($metadata, true); return $queries; } @@ -81,7 +80,7 @@ protected function getUpdateQueries() */ protected function getIgnoredQueries() { - if ($this->ignoredQueriesFile === NULL) { + if ($this->ignoredQueriesFile === null) { return []; } @@ -90,5 +89,4 @@ protected function getIgnoredQueries() return $queries; } - } diff --git a/src/Bridges/NetteDI/MigrationsExtension.php b/src/Bridges/NetteDI/MigrationsExtension.php index 8f3e917..1fe0b95 100644 --- a/src/Bridges/NetteDI/MigrationsExtension.php +++ b/src/Bridges/NetteDI/MigrationsExtension.php @@ -9,6 +9,7 @@ namespace Nextras\Migrations\Bridges\NetteDI; +use Doctrine; use Nette; use Nette\DI\ContainerBuilder; use Nette\Utils\Strings; @@ -26,15 +27,15 @@ class MigrationsExtension extends Nette\DI\CompilerExtension /** @var array */ public $defaults = [ - 'dir' => NULL, + 'dir' => null, 'phpParams' => [], - 'driver' => NULL, - 'dbal' => NULL, + 'driver' => null, + 'dbal' => null, 'printer' => 'console', - 'groups' => NULL, // null|array - 'diffGenerator' => TRUE, // false|doctrine - 'withDummyData' => FALSE, - 'ignoredQueriesFile' => NULL, + 'groups' => null, // null|array + 'diffGenerator' => true, // false|doctrine + 'withDummyData' => false, + 'ignoredQueriesFile' => null, ]; /** @var array */ @@ -59,6 +60,7 @@ class MigrationsExtension extends Nette\DI\CompilerExtension 'psrLog' => 'Nextras\Migrations\Bridges\PsrLog\PsrLogPrinter', ]; + public function loadConfiguration() { $config = $this->validateConfig($this->defaults); @@ -82,7 +84,7 @@ public function loadConfiguration() } // groups - if ($config['groups'] === NULL) { + if ($config['groups'] === null) { Validators::assertField($config, 'dir', 'string|Nette\PhpGenerator\PhpLiteral'); Validators::assertField($config, 'withDummyData', 'bool'); $config['groups'] = $this->createDefaultGroupConfiguration($config['dir'], $config['withDummyData']); @@ -126,7 +128,7 @@ public function beforeCompile() } // diff generator - if ($config['diffGenerator'] === TRUE) { + if ($config['diffGenerator'] === true) { if ($builder->findByType('Doctrine\ORM\EntityManagerInterface') && $builder->hasDefinition($this->prefix('group.structures'))) { Validators::assertField($config, 'ignoredQueriesFile', 'null|string'); $diffGenerator = $this->createDoctrineStructureDiffGeneratorDefinition($config['ignoredQueriesFile']); @@ -166,7 +168,7 @@ private function getDbalDefinition($dbal) ->setClass('Nextras\Migrations\IDbal') ->setFactory($factory); - } elseif ($dbal === NULL) { + } elseif ($dbal === null) { return '@Nextras\Migrations\IDbal'; } else { @@ -187,7 +189,7 @@ private function getDbalFactory($dbal) return $dbal; } else { - return NULL; + return null; } } @@ -202,7 +204,7 @@ private function getDriverDefinition($driver, $dbal) ->setClass('Nextras\Migrations\IDriver') ->setFactory($factory); - } elseif ($driver === NULL) { + } elseif ($driver === null) { return '@Nextras\Migrations\IDriver'; } else { @@ -220,7 +222,7 @@ private function getDriverFactory($driver, $dbal) return new Nette\DI\Statement($this->drivers[$driver], [$dbal]); } else { - return NULL; + return null; } } @@ -235,7 +237,7 @@ private function getPrinterDefinition($printer) ->setClass('Nextras\Migrations\IPrinter') ->setFactory($factory); - } elseif ($printer === NULL) { + } elseif ($printer === null) { return '@Nextras\Migrations\IPrinter'; } else { @@ -256,7 +258,7 @@ private function getPrinterFactory($printer) return $printer; } else { - return NULL; + return null; } } @@ -293,7 +295,7 @@ private function createDefaultGroupConfiguration($dir, $withDummyData) foreach ($groups as $groupName => $groupConfig) { $serviceName = $this->prefix("diffGenerator.$groupName"); - $diffGenerator = $builder->hasDefinition($serviceName) ? $builder->getDefinition($serviceName) : NULL; + $diffGenerator = $builder->hasDefinition($serviceName) ? $builder->getDefinition($serviceName) : null; $groups[$groupName]['generator'] = $diffGenerator; } @@ -317,7 +319,7 @@ private function createGroupDefinitions(array $groups) $serviceName = lcfirst(str_replace('-', '', ucwords($groupName, '-'))); $groupDefinitions[] = $builder->addDefinition($this->prefix("group.$serviceName")) ->addTag(self::TAG_GROUP, ['for' => [$this->name]]) - ->setAutowired(FALSE) + ->setAutowired(false) ->setClass('Nextras\Migrations\Entities\Group') ->addSetup('$name', [$groupName]) ->addSetup('$enabled', [$enabled]) @@ -336,14 +338,14 @@ private function createExtensionHandlerDefinitions($driver, $phpParams) $sqlHandler = $builder->addDefinition($this->prefix('extensionHandler.sql')) ->addTag(self::TAG_EXTENSION_HANDLER, ['for' => [$this->name], 'extension' => 'sql']) - ->setAutowired(FALSE) + ->setAutowired(false) ->setClass('Nextras\Migrations\Extensions\SqlHandler') ->setArguments([$driver]); $phpHandler = $builder->addDefinition($this->prefix('extensionHandler.php')) ->addTag(self::TAG_EXTENSION_HANDLER, ['for' => [$this->name], 'extension' => 'php']) ->setClass('Nextras\Migrations\Extensions\PhpHandler') - ->setAutowired(FALSE) + ->setAutowired(false) ->setArguments([$phpParams]); return [$sqlHandler, $phpHandler]; @@ -364,7 +366,7 @@ private function createDoctrineStructureDiffGeneratorDefinition($ignoredQueriesF $builder = $this->getContainerBuilder(); return $builder->addDefinition($this->prefix('diffGenerator.structures')) - ->setAutowired(FALSE) + ->setAutowired(false) ->setClass('Nextras\Migrations\IDiffGenerator') ->setFactory('Nextras\Migrations\Bridges\DoctrineOrm\StructureDiffGenerator') ->setArguments(['@Doctrine\ORM\EntityManagerInterface', $ignoredQueriesFile]); diff --git a/src/Bridges/NetteDatabase/NetteAdapter.php b/src/Bridges/NetteDatabase/NetteAdapter.php index 9ca8202..fc4f260 100644 --- a/src/Bridges/NetteDatabase/NetteAdapter.php +++ b/src/Bridges/NetteDatabase/NetteAdapter.php @@ -70,5 +70,4 @@ public function escapeIdentifier($value) { return $this->conn->getSupplementalDriver()->delimite($value); } - } diff --git a/src/Bridges/NextrasDbal/NextrasAdapter.php b/src/Bridges/NextrasDbal/NextrasAdapter.php index e6d2526..8dade0b 100644 --- a/src/Bridges/NextrasDbal/NextrasAdapter.php +++ b/src/Bridges/NextrasDbal/NextrasAdapter.php @@ -108,5 +108,4 @@ public function escapeIdentifier($value) return $this->conn->getDriver()->convertToSql($value, IDriver::TYPE_IDENTIFIER); } } - } diff --git a/src/Bridges/SymfonyBundle/DependencyInjection/NextrasMigrationsExtension.php b/src/Bridges/SymfonyBundle/DependencyInjection/NextrasMigrationsExtension.php index eded90b..e358630 100644 --- a/src/Bridges/SymfonyBundle/DependencyInjection/NextrasMigrationsExtension.php +++ b/src/Bridges/SymfonyBundle/DependencyInjection/NextrasMigrationsExtension.php @@ -45,7 +45,7 @@ public function load(array $configs, ContainerBuilder $container) $dbalAlias = $config['dbal']; $dbalDefinition = new Definition($this->dbals[$dbalAlias]); - $dbalDefinition->setAutowired(TRUE); + $dbalDefinition->setAutowired(true); $driverAlias = $config['driver']; $driverDefinition = new Definition($this->drivers[$driverAlias]); @@ -53,7 +53,7 @@ public function load(array $configs, ContainerBuilder $container) $printerAlias = $config['printer']; $printerDefinition = new Definition($this->printers[$printerAlias]); - $printerDefinition->setAutowired(TRUE); + $printerDefinition->setAutowired(true); $container->addDefinitions([ 'nextras_migrations.dbal' => $dbalDefinition, @@ -69,11 +69,11 @@ public function load(array $configs, ContainerBuilder $container) if ($config['diff_generator'] === 'doctrine') { $structureDiffGeneratorDefinition = new Definition('Nextras\Migrations\Bridges\DoctrineOrm\StructureDiffGenerator'); - $structureDiffGeneratorDefinition->setAutowired(TRUE); + $structureDiffGeneratorDefinition->setAutowired(true); $structureDiffGeneratorDefinition->setArgument('$ignoredQueriesFile', $config['ignored_queries_file']); } else { - $structureDiffGeneratorDefinition = NULL; + $structureDiffGeneratorDefinition = null; } foreach ($config['php_params'] as $phpParamKey => $phpParamValue) { diff --git a/src/Bridges/SymfonyConsole/BaseCommand.php b/src/Bridges/SymfonyConsole/BaseCommand.php index 213abb4..02b34fe 100644 --- a/src/Bridges/SymfonyConsole/BaseCommand.php +++ b/src/Bridges/SymfonyConsole/BaseCommand.php @@ -55,5 +55,4 @@ protected function runMigrations($mode, $config) return 0; } - } diff --git a/src/Bridges/SymfonyConsole/ContinueCommand.php b/src/Bridges/SymfonyConsole/ContinueCommand.php index 659059a..9035ed4 100644 --- a/src/Bridges/SymfonyConsole/ContinueCommand.php +++ b/src/Bridges/SymfonyConsole/ContinueCommand.php @@ -34,5 +34,4 @@ protected function execute(InputInterface $input, OutputInterface $output) { return $this->runMigrations(Runner::MODE_CONTINUE, $this->config); } - } diff --git a/src/Bridges/SymfonyConsole/CreateCommand.php b/src/Bridges/SymfonyConsole/CreateCommand.php index 53e7e19..3c38d4e 100644 --- a/src/Bridges/SymfonyConsole/CreateCommand.php +++ b/src/Bridges/SymfonyConsole/CreateCommand.php @@ -58,9 +58,9 @@ protected function configure() $this->addArgument('type', InputArgument::REQUIRED, $this->getTypeArgDescription()); $this->addArgument('label', InputArgument::REQUIRED, 'short description'); - $this->addOption('empty', NULL, InputOption::VALUE_NONE, 'create empty file'); - $this->addOption('diff', NULL, InputOption::VALUE_NONE, 'use schema diff as file content'); - $this->addOption('stdin', NULL, InputOption::VALUE_NONE, 'use stdin as file content'); + $this->addOption('empty', null, InputOption::VALUE_NONE, 'create empty file'); + $this->addOption('diff', null, InputOption::VALUE_NONE, 'use schema diff as file content'); + $this->addOption('stdin', null, InputOption::VALUE_NONE, 'use stdin as file content'); } @@ -171,11 +171,11 @@ class_exists('Symfony\Component\String\Slugger\AsciiSlugger') /** - * @param string $dir + * @param string $dir * @param string|NULL $found * @return bool */ - protected function hasNumericSubdirectory($dir, & $found) + protected function hasNumericSubdirectory($dir, &$found) { $items = @scandir($dir); // directory may not exist @@ -183,12 +183,12 @@ protected function hasNumericSubdirectory($dir, & $found) foreach ($items as $item) { if ($item !== '.' && $item !== '..' && is_dir($dir . '/' . $item)) { $found = $dir . '/' . $item; - return TRUE; + return true; } } } - return FALSE; + return false; } @@ -249,7 +249,7 @@ protected function getFileContentSource(InputInterface $input) */ protected function getFileContent(Group $group, $source) { - if ($source === self::CONTENT_SOURCE_DIFF && $group->generator !== NULL) { + if ($source === self::CONTENT_SOURCE_DIFF && $group->generator !== null) { return $group->generator->generateContent(); } elseif ($source === self::CONTENT_SOURCE_STDIN) { @@ -269,12 +269,11 @@ protected function getFileContent(Group $group, $source) */ protected function createFile($path, $content, OutputInterface $output) { - @mkdir(dirname($path), 0777, TRUE); // directory may already exist + @mkdir(dirname($path), 0777, true); // directory may already exist if (file_put_contents("$path.tmp", $content) !== strlen($content) || !rename("$path.tmp", $path)) { $output->writeln("Unable to write to '$path'."); exit(1); } } - } diff --git a/src/Bridges/SymfonyConsole/ResetCommand.php b/src/Bridges/SymfonyConsole/ResetCommand.php index ec79fce..51a2aa6 100644 --- a/src/Bridges/SymfonyConsole/ResetCommand.php +++ b/src/Bridges/SymfonyConsole/ResetCommand.php @@ -22,6 +22,7 @@ class ResetCommand extends BaseCommand /** @var string */ protected static $defaultDescription = 'Drops current database and recreates it from scratch'; + protected function configure() { $this->setName(self::$defaultName); @@ -34,5 +35,4 @@ protected function execute(InputInterface $input, OutputInterface $output) { return $this->runMigrations(Runner::MODE_RESET, $this->config); } - } diff --git a/src/Configurations/Configuration.php b/src/Configurations/Configuration.php index e05d85f..8e781e3 100644 --- a/src/Configurations/Configuration.php +++ b/src/Configurations/Configuration.php @@ -27,8 +27,8 @@ class Configuration implements IConfiguration /** - * @param Group[] $groups - * @param IExtensionHandler[] $extensionHandlers (extension => IExtensionHandler) + * @param Group[] $groups + * @param IExtensionHandler[] $extensionHandlers (extension => IExtensionHandler) */ public function __construct(array $groups, array $extensionHandlers) { diff --git a/src/Configurations/DefaultConfiguration.php b/src/Configurations/DefaultConfiguration.php index c38819b..cd9ccc2 100644 --- a/src/Configurations/DefaultConfiguration.php +++ b/src/Configurations/DefaultConfiguration.php @@ -55,7 +55,7 @@ class DefaultConfiguration implements IConfiguration * @param bool $withDummyData * @param array $phpParams */ - public function __construct($dir, IDriver $driver, $withDummyData = TRUE, array $phpParams = []) + public function __construct($dir, IDriver $driver, $withDummyData = true, array $phpParams = []) { $this->dir = $dir; $this->driver = $driver; @@ -69,16 +69,16 @@ public function __construct($dir, IDriver $driver, $withDummyData = TRUE, array */ public function getGroups() { - if ($this->groups === NULL) { + if ($this->groups === null) { $structures = new Group(); - $structures->enabled = TRUE; + $structures->enabled = true; $structures->name = 'structures'; $structures->directory = $this->dir . '/structures'; $structures->dependencies = []; $structures->generator = $this->structureDiffGenerator; $basicData = new Group(); - $basicData->enabled = TRUE; + $basicData->enabled = true; $basicData->name = 'basic-data'; $basicData->directory = $this->dir . '/basic-data'; $basicData->dependencies = ['structures']; @@ -102,7 +102,7 @@ public function getGroups() */ public function getExtensionHandlers() { - if ($this->handlers === NULL) { + if ($this->handlers === null) { $this->handlers = [ 'sql' => new SqlHandler($this->driver), 'php' => new PhpHandler($this->phpParams), @@ -117,7 +117,7 @@ public function getExtensionHandlers() * @param IDiffGenerator|NULL $generator * @return void */ - public function setStructureDiffGenerator(IDiffGenerator $generator = NULL) + public function setStructureDiffGenerator(IDiffGenerator $generator = null) { $this->structureDiffGenerator = $generator; } @@ -127,9 +127,8 @@ public function setStructureDiffGenerator(IDiffGenerator $generator = NULL) * @param IDiffGenerator|NULL $generator * @return void */ - public function setDummyDataDiffGenerator(IDiffGenerator $generator = NULL) + public function setDummyDataDiffGenerator(IDiffGenerator $generator = null) { $this->dummyDataDiffGenerator = $generator; } - } diff --git a/src/Controllers/BaseController.php b/src/Controllers/BaseController.php index 3e1ab5a..b61ce93 100644 --- a/src/Controllers/BaseController.php +++ b/src/Controllers/BaseController.php @@ -32,20 +32,20 @@ public function __construct(IDriver $driver) $printer = $this->createPrinter(); $this->runner = new Engine\Runner($driver, $printer); $this->mode = Engine\Runner::MODE_CONTINUE; - $this->groups = array(); + $this->groups = []; } abstract public function run(); - public function addGroup($name, $dir, array $dependencies = array()) + public function addGroup($name, $dir, array $dependencies = []) { $group = new Group; $group->name = $name; $group->directory = $dir; $group->dependencies = $dependencies; - $group->enabled = FALSE; + $group->enabled = false; $this->groups[$name] = $group; return $this; @@ -61,7 +61,7 @@ public function addExtension($extension, IExtensionHandler $handler) protected function registerGroups() { - $enabled = array(); + $enabled = []; foreach ($this->groups as $group) { $this->runner->addGroup($group); if ($group->enabled) { @@ -80,5 +80,4 @@ protected function setupPhp() abstract protected function createPrinter(); - } diff --git a/src/Controllers/ConsoleController.php b/src/Controllers/ConsoleController.php index fce2de7..155c6a2 100644 --- a/src/Controllers/ConsoleController.php +++ b/src/Controllers/ConsoleController.php @@ -39,7 +39,7 @@ private function processArguments() { $arguments = array_slice($_SERVER['argv'], 1); $help = count($arguments) === 0; - $groups = $error = FALSE; + $groups = $error = false; foreach ($arguments as $argument) { if (strncmp($argument, '--', 2) === 0) { @@ -48,25 +48,25 @@ private function processArguments() } elseif ($argument === '--init-sql') { $this->mode = Engine\Runner::MODE_INIT; } elseif ($argument === '--help') { - $help = TRUE; + $help = true; } else { fprintf(STDERR, "Warning: Unknown option '%s'\n", $argument); continue; } } else { if (isset($this->groups[$argument])) { - $this->groups[$argument]->enabled = TRUE; - $groups = TRUE; + $this->groups[$argument]->enabled = true; + $groups = true; } else { fprintf(STDERR, "Error: Unknown group '%s'\n", $argument); - $error = TRUE; + $error = true; } } } if (!$groups && !$help) { fprintf(STDERR, "Error: At least one group must be enabled.\n"); - $error = TRUE; + $error = true; } if ($error) { diff --git a/src/Controllers/HttpController.php b/src/Controllers/HttpController.php index 5757cd7..da203ac 100644 --- a/src/Controllers/HttpController.php +++ b/src/Controllers/HttpController.php @@ -32,7 +32,7 @@ public function run() private function processArguments() { if (isset($_GET['action'])) { - if ($_GET['action'] === 'run' || $_GET['action'] === 'css') { + if ($_GET['action'] === 'run' || $_GET['action'] === 'css') { $this->action = $_GET['action']; } else { $this->action = 'error'; @@ -46,7 +46,7 @@ private function processArguments() foreach ($_GET['groups'] as $group) { if (is_string($group)) { if (isset($this->groups[$group])) { - $this->groups[$group]->enabled = TRUE; + $this->groups[$group]->enabled = true; } else { $error = sprintf( "Unknown group '%s', the following groups are registered: '%s'", @@ -99,11 +99,11 @@ private function actionIndex() $combinations = $this->getGroupsCombinations(); $this->printHeader(); - $modes = array( + $modes = [ 0 => '

Continue

', 1 => '

Reset All tables, views and data will be destroyed!

', 2 => '

Init SQL

', - ); + ]; echo "

Migrations

\n"; foreach ($modes as $mode => $heading) { @@ -111,7 +111,7 @@ private function actionIndex() echo "$heading\n"; echo "
    \n"; foreach ($combinations as $combination) { - $query = htmlspecialchars(http_build_query(array('action' => 'run' , 'groups' => $combination, 'mode' => $mode))); + $query = htmlspecialchars(http_build_query(['action' => 'run', 'groups' => $combination, 'mode' => $mode])); $text = htmlspecialchars(implode(' + ', $combination)); $alert = $mode === 1 ? ' onclick="return confirm(\'Are you really sure?\')"' : ''; echo "\t
  • Run $text\n"; @@ -137,7 +137,7 @@ private function actionRun() private function actionCss() { - header('Content-Type: text/css', TRUE); + header('Content-Type: text/css', true); readfile(__DIR__ . '/templates/main.css'); } @@ -146,22 +146,22 @@ private function actionError() { $this->printHeader(); echo "

    Migrations – error

    \n"; - echo "
    " . nl2br(htmlspecialchars($this->error), FALSE) . "
    \n"; + echo "
    " . nl2br(htmlspecialchars($this->error), false) . "
    \n"; } private function getGroupsCombinations() { - $groups = array(); + $groups = []; $index = 1; foreach ($this->groups as $group) { $groups[$index] = $group; $index = ($index << 1); } - $combinations = array(); + $combinations = []; for ($i = 1; true; $i++) { - $combination = array(); + $combination = []; foreach ($groups as $key => $group) { if ($i & $key) { $combination[] = $group->name; @@ -193,5 +193,4 @@ protected function createPrinter() { return new Printers\HtmlDump(); } - } diff --git a/src/Drivers/BaseDriver.php b/src/Drivers/BaseDriver.php index 970851b..b9f1a04 100644 --- a/src/Drivers/BaseDriver.php +++ b/src/Drivers/BaseDriver.php @@ -27,13 +27,13 @@ abstract class BaseDriver implements IDriver /** @var string */ protected $tableName; - /** @var NULL|string */ + /** @var null|string */ protected $tableNameQuoted; /** - * @param IDbal $dbal - * @param string $tableName + * @param IDbal $dbal + * @param string $tableName */ public function __construct(IDbal $dbal, $tableName = 'migrations') { @@ -63,7 +63,7 @@ public function setupConnection() public function loadFile($path) { $content = @file_get_contents($path); - if ($content === FALSE) { + if ($content === false) { throw new IOException("Cannot open file '$path'."); } @@ -85,7 +85,7 @@ public function loadFile($path) '[' => '(]|\z)', ]; - while (TRUE) { + while (true) { while (preg_match($delimiterRe, $content, $match, 0, $queryOffset)) { $delimiter = $match[1]; $queryOffset += strlen($match[0]); @@ -93,7 +93,7 @@ public function loadFile($path) $parseRe = '(' . preg_quote($delimiter) . "|$openRe)"; } - while (TRUE) { + while (true) { preg_match($parseRe, $content, $match, PREG_OFFSET_CAPTURE, $parseOffset); // should always match $found = $match[0][0]; $parseOffset = $match[0][1] + strlen($found); @@ -136,5 +136,4 @@ public function loadFile($path) return $queries; } - } diff --git a/src/Drivers/MySqlDriver.php b/src/Drivers/MySqlDriver.php index 9049cae..9390991 100644 --- a/src/Drivers/MySqlDriver.php +++ b/src/Drivers/MySqlDriver.php @@ -105,7 +105,7 @@ public function insertMigration(Migration $migration) $this->dbal->escapeString($migration->filename) . "," . $this->dbal->escapeString($migration->checksum) . "," . $this->dbal->escapeDateTime($migration->executedAt) . "," . - $this->dbal->escapeBool(FALSE) . + $this->dbal->escapeBool(false) . ") "); @@ -125,7 +125,7 @@ public function markMigrationAsReady(Migration $migration) public function getAllMigrations() { - $migrations = array(); + $migrations = []; $result = $this->dbal->query("SELECT * FROM {$this->tableNameQuoted} ORDER BY `executed`"); foreach ($result as $row) { if (is_string($row['executed'])) { @@ -180,10 +180,9 @@ public function getInitMigrationsSource(array $files) $this->dbal->escapeString($file->name) . ", " . $this->dbal->escapeString($file->checksum) . ", " . $this->dbal->escapeDateTime(new DateTime('now')) . ", " . - $this->dbal->escapeBool(TRUE) . + $this->dbal->escapeBool(true) . ");\n"; } return $out; } - } diff --git a/src/Drivers/PgSqlDriver.php b/src/Drivers/PgSqlDriver.php index b86ffaa..46d0dea 100644 --- a/src/Drivers/PgSqlDriver.php +++ b/src/Drivers/PgSqlDriver.php @@ -26,14 +26,14 @@ class PgSqlDriver extends BaseDriver implements IDriver /** @var string */ protected $schema; - /** @var NULL|string */ + /** @var null|string */ protected $schemaQuoted; /** - * @param IDbal $dbal - * @param string $tableName - * @param string $schema + * @param IDbal $dbal + * @param string $tableName + * @param string $schema */ public function __construct(IDbal $dbal, $tableName = 'migrations', $schema = 'public') { @@ -117,7 +117,7 @@ public function insertMigration(Migration $migration) $this->dbal->escapeString($migration->filename) . "," . $this->dbal->escapeString($migration->checksum) . "," . $this->dbal->escapeDateTime($migration->executedAt) . "," . - $this->dbal->escapeBool(FALSE) . + $this->dbal->escapeBool(false) . ") RETURNING id "); @@ -138,7 +138,7 @@ public function markMigrationAsReady(Migration $migration) public function getAllMigrations() { - $migrations = array(); + $migrations = []; $result = $this->dbal->query("SELECT * FROM {$this->schemaQuoted}.{$this->tableNameQuoted} ORDER BY \"executed\""); foreach ($result as $row) { if (is_string($row['executed'])) { @@ -193,10 +193,9 @@ public function getInitMigrationsSource(array $files) $this->dbal->escapeString($file->name) . ", " . $this->dbal->escapeString($file->checksum) . ", " . $this->dbal->escapeDateTime(new DateTime('now')) . ", " . - $this->dbal->escapeBool(TRUE) . + $this->dbal->escapeBool(true) . ");\n"; } return $out; } - } diff --git a/src/Engine/Finder.php b/src/Engine/Finder.php index 607da94..3fb9d1b 100644 --- a/src/Engine/Finder.php +++ b/src/Engine/Finder.php @@ -9,8 +9,8 @@ namespace Nextras\Migrations\Engine; -use Nextras\Migrations\Entities\Group; use Nextras\Migrations\Entities\File; +use Nextras\Migrations\Entities\Group; use Nextras\Migrations\Exception; use Nextras\Migrations\IOException; use Nextras\Migrations\LogicException; @@ -28,7 +28,7 @@ class Finder */ public function find(array $groups, array $extensions) { - $files = array(); + $files = []; foreach ($groups as $group) { if (!$group->enabled) { continue; @@ -51,6 +51,7 @@ public function find(array $groups, array $extensions) /** * Returns logical name of migration file. + * * @param string $path relative path to group directory * @return string */ @@ -66,6 +67,7 @@ protected function getName($path) /** * Returns file extension. + * * @param File $file * @param string[] $extensions * @return string @@ -73,11 +75,11 @@ protected function getName($path) */ protected function getExtension(File $file, array $extensions) { - $fileExt = NULL; + $fileExt = null; foreach ($extensions as $extension) { if (substr($file->name, -strlen($extension)) === $extension) { - if ($fileExt !== NULL) { + if ($fileExt !== null) { throw new LogicException(sprintf( 'Finder: Extension of "%s" is ambiguous, both "%s" and "%s" can be used.', $file->group->directory . '/' . $file->name, $fileExt, $extension @@ -89,7 +91,7 @@ protected function getExtension(File $file, array $extensions) } } - if ($fileExt === NULL) { + if ($fileExt === null) { throw new LogicException(sprintf( 'Finder: No extension matched "%s". Supported extensions are %s.', $file->group->directory . '/' . $file->name, '"' . implode('", "', $extensions) . '"' @@ -107,7 +109,7 @@ protected function getExtension(File $file, array $extensions) protected function getChecksum(File $file) { $content = @file_get_contents($file->path); - if ($content === FALSE) { + if ($content === false) { throw new IOException("Unable to read '$file->path'."); } @@ -116,7 +118,7 @@ protected function getChecksum(File $file) /** - * @param string $dir + * @param string $dir * @return string[] * @throws IOException */ @@ -149,5 +151,4 @@ protected function getItems($dir) { return @scandir($dir) ?: []; // directory may not exist } - } diff --git a/src/Engine/OrderResolver.php b/src/Engine/OrderResolver.php index 6e92656..9dcecfb 100644 --- a/src/Engine/OrderResolver.php +++ b/src/Engine/OrderResolver.php @@ -142,9 +142,9 @@ protected function sortFiles(array $files, array $groups) /** - * Returns TRUE if groupA depends on groupB. + * Returns true if groupA depends on groupB. * - * @param array $groups (name => Group) + * @param array $groups (name => Group) * @param Group $groupA * @param Group $groupB * @return bool @@ -160,21 +160,21 @@ protected function isGroupDependentOn(array $groups, Group $groupA, Group $group } if ($groupA->name === $node) { - return TRUE; + return true; } - $visited[$node] = TRUE; + $visited[$node] = true; foreach ($groups[$node]->dependencies as $dep) { $queue[] = $dep; } } - return FALSE; + return false; } protected function getAssocMigrations(array $migrations) { - $assoc = array(); + $assoc = []; foreach ($migrations as $migration) { $assoc[$migration->group][$migration->filename] = $migration; } @@ -184,7 +184,7 @@ protected function getAssocMigrations(array $migrations) protected function getAssocGroups(array $groups) { - $assoc = array(); + $assoc = []; foreach ($groups as $group) { $assoc[$group->name] = $group; } @@ -194,7 +194,7 @@ protected function getAssocGroups(array $groups) protected function getAssocFiles(array $files) { - $assoc = array(); + $assoc = []; foreach ($files as $file) { $assoc[$file->group->name][$file->name] = $file; } @@ -204,7 +204,7 @@ protected function getAssocFiles(array $files) protected function getFlatFiles(array $files) { - $flat = array(); + $flat = []; foreach ($files as $tmp) { foreach ($tmp as $file) { $flat[] = $file; @@ -254,5 +254,4 @@ private function validateGroups(array $groups) } } } - } diff --git a/src/Engine/Runner.php b/src/Engine/Runner.php index b36b240..8f6aa21 100644 --- a/src/Engine/Runner.php +++ b/src/Engine/Runner.php @@ -34,10 +34,10 @@ class Runner private $printer; /** @var array (extension => IExtensionHandler) */ - private $extensionsHandlers = array(); + private $extensionsHandlers = []; /** @var Group[] */ - private $groups = array(); + private $groups = []; /** @var IDriver */ private $driver; @@ -86,7 +86,7 @@ public function addExtensionHandler($extension, IExtensionHandler $handler) * @param IConfiguration $config * @return void */ - public function run($mode = self::MODE_CONTINUE, IConfiguration $config = NULL) + public function run($mode = self::MODE_CONTINUE, IConfiguration $config = null) { if ($config) { foreach ($config->getGroups() as $group) { @@ -102,7 +102,7 @@ public function run($mode = self::MODE_CONTINUE, IConfiguration $config = NULL) $this->driver->setupConnection(); $this->printer->printSource($this->driver->getInitTableSource() . "\n"); $files = $this->finder->find($this->groups, array_keys($this->extensionsHandlers)); - $files = $this->orderResolver->resolve(array(), $this->groups, $files, self::MODE_RESET); + $files = $this->orderResolver->resolve([], $this->groups, $files, self::MODE_RESET); $this->printer->printSource($this->driver->getInitMigrationsSource($files)); return; } @@ -124,9 +124,9 @@ public function run($mode = self::MODE_CONTINUE, IConfiguration $config = NULL) $this->printer->printToExecute($toExecute); foreach ($toExecute as $file) { - $time = microtime(TRUE); + $time = microtime(true); $queriesCount = $this->execute($file); - $this->printer->printExecute($file, $queriesCount, microtime(TRUE) - $time); + $this->printer->printExecute($file, $queriesCount, microtime(true) - $time); } $this->driver->unlock(); @@ -183,5 +183,4 @@ protected function execute(File $file) return $queriesCount; } - } diff --git a/src/Entities/File.php b/src/Entities/File.php index ef601d3..1ad8cf6 100644 --- a/src/Entities/File.php +++ b/src/Entities/File.php @@ -30,5 +30,4 @@ class File /** @var string */ public $checksum; - } diff --git a/src/Entities/Group.php b/src/Entities/Group.php index a7655a9..e605c17 100644 --- a/src/Entities/Group.php +++ b/src/Entities/Group.php @@ -29,7 +29,6 @@ class Group /** @var string[] */ public $dependencies; - /** @var IDiffGenerator|NULL */ + /** @var IDiffGenerator|null */ public $generator; - } diff --git a/src/Entities/Migration.php b/src/Entities/Migration.php index a486305..9e9b64e 100644 --- a/src/Entities/Migration.php +++ b/src/Entities/Migration.php @@ -35,5 +35,4 @@ class Migration /** @var bool */ public $completed; - } diff --git a/src/Extensions/PhpHandler.php b/src/Extensions/PhpHandler.php index 32b6ef1..d73e81c 100644 --- a/src/Extensions/PhpHandler.php +++ b/src/Extensions/PhpHandler.php @@ -25,7 +25,7 @@ class PhpHandler implements IExtensionHandler /** - * @param array $params name => value + * @param array $params name => value */ public function __construct(array $params = []) { @@ -62,10 +62,9 @@ public function execute(File $file) { extract($this->params, EXTR_SKIP); $count = @include $file->path; - if ($count === FALSE) { + if ($count === false) { throw new IOException("Cannot include file '{$file->path}'."); } return $count; } - } diff --git a/src/Extensions/SqlHandler.php b/src/Extensions/SqlHandler.php index 492ce88..cdfd8c9 100644 --- a/src/Extensions/SqlHandler.php +++ b/src/Extensions/SqlHandler.php @@ -25,7 +25,7 @@ class SqlHandler implements IExtensionHandler /** - * @param IDriver $driver + * @param IDriver $driver */ public function __construct(IDriver $driver) { @@ -45,5 +45,4 @@ public function execute(File $file) } return $count; } - } diff --git a/src/IConfiguration.php b/src/IConfiguration.php index cd7fac3..1137c0d 100644 --- a/src/IConfiguration.php +++ b/src/IConfiguration.php @@ -27,5 +27,4 @@ public function getGroups(); * @return array (extension => IExtensionHandler) */ public function getExtensionHandlers(); - } diff --git a/src/IDiffGenerator.php b/src/IDiffGenerator.php index b5f91f1..4e0d542 100644 --- a/src/IDiffGenerator.php +++ b/src/IDiffGenerator.php @@ -18,9 +18,9 @@ interface IDiffGenerator */ function getExtension(); + /** * @return string SQL (semicolon-separated queries) */ function generateContent(); - } diff --git a/src/IDriver.php b/src/IDriver.php index 5f7a20d..137015d 100644 --- a/src/IDriver.php +++ b/src/IDriver.php @@ -9,8 +9,8 @@ namespace Nextras\Migrations; -use Nextras\Migrations\Entities\Migration; use Nextras\Migrations\Entities\File; +use Nextras\Migrations\Entities\Migration; /** @@ -30,6 +30,7 @@ function setupConnection(); /** * Drops the database / schema. Should removes all db objects (tables, views, procedures, sequences, ...) + * * @return mixed */ function emptyDatabase(); @@ -37,6 +38,7 @@ function emptyDatabase(); /** * Loads and executes SQL queries from given file. + * * @param string $path * @return int number of executed queries */ @@ -87,6 +89,7 @@ function dropTable(); /** * Inserts migration info into migration table. + * * @param Migration $migration */ function insertMigration(Migration $migration); @@ -94,6 +97,7 @@ function insertMigration(Migration $migration); /** * Updated migration as executed. + * * @param Migration $migration */ function markMigrationAsReady(Migration $migration); @@ -101,6 +105,7 @@ function markMigrationAsReady(Migration $migration); /** * Returns all migrations stored in migration table sorted by time. + * * @return Migration[] */ function getAllMigrations(); @@ -108,6 +113,7 @@ function getAllMigrations(); /** * Returns source code for migration table initialization. + * * @return string */ function getInitTableSource(); @@ -115,9 +121,9 @@ function getInitTableSource(); /** * Returns source code for migration table data initialization. + * * @param File[] $files * @return string */ function getInitMigrationsSource(array $files); - } diff --git a/src/IExtensionHandler.php b/src/IExtensionHandler.php index 7f36f56..1baec2c 100644 --- a/src/IExtensionHandler.php +++ b/src/IExtensionHandler.php @@ -23,5 +23,4 @@ interface IExtensionHandler * @return int number of queries */ function execute(File $file); - } diff --git a/src/IPrinter.php b/src/IPrinter.php index 586bc3c..5cdb364 100644 --- a/src/IPrinter.php +++ b/src/IPrinter.php @@ -21,6 +21,7 @@ interface IPrinter * Print general info about mode. * - reset = Database has been wiped. * - continue = Running new migrations. + * * @param string $mode */ function printIntro($mode); @@ -28,6 +29,7 @@ function printIntro($mode); /** * List of migrations which should be executed has been completed. + * * @param File[] $toExecute */ function printToExecute(array $toExecute); @@ -35,9 +37,10 @@ function printToExecute(array $toExecute); /** * A migration has been successfully executed. - * @param File $file - * @param int $count number of executed queries - * @param float $time elapsed time in milliseconds + * + * @param File $file + * @param int $count number of executed queries + * @param float $time elapsed time in milliseconds */ function printExecute(File $file, $count, $time); @@ -50,6 +53,7 @@ function printDone(); /** * An error has occurred during execution of a migration. + * * @param Exception $e */ function printError(Exception $e); @@ -57,8 +61,8 @@ function printError(Exception $e); /** * Prints init source code. + * * @param string $code */ function printSource($code); - } diff --git a/src/Printers/Console.php b/src/Printers/Console.php index 1ecf23d..37f24f1 100644 --- a/src/Printers/Console.php +++ b/src/Printers/Console.php @@ -85,12 +85,13 @@ public function printSource($code) /** * Prints text to a console, optionally in a specific color. + * * @param string $s * @param string|NULL $color self::COLOR_* */ - protected function output($s, $color = NULL) + protected function output($s, $color = null) { - if ($color === NULL || !$this->useColors) { + if ($color === null || !$this->useColors) { echo "$s\n"; } else { echo $this->color($s, $color) . "\n"; @@ -113,14 +114,13 @@ protected function color($s, $color) /** - * @author David Grudl - * @license New BSD License * @return bool TRUE if terminal support colors, FALSE otherwise + * @license New BSD License + * @author David Grudl */ protected function detectColorSupport() { - return (getenv('ConEmuANSI') === 'ON' || getenv('ANSICON') !== FALSE + return (getenv('ConEmuANSI') === 'ON' || getenv('ANSICON') !== false || (defined('STDOUT') && function_exists('posix_isatty') && posix_isatty(STDOUT))); } - } diff --git a/src/Printers/DevNull.php b/src/Printers/DevNull.php index 5a26677..15080bd 100644 --- a/src/Printers/DevNull.php +++ b/src/Printers/DevNull.php @@ -16,6 +16,7 @@ /** * /dev/null printer + * * @author Petr Procházka */ class DevNull implements IPrinter diff --git a/src/Printers/HtmlDump.php b/src/Printers/HtmlDump.php index 0557578..6a832a9 100644 --- a/src/Printers/HtmlDump.php +++ b/src/Printers/HtmlDump.php @@ -81,7 +81,7 @@ public function printSource($code) /** - * @param string $s HTML string + * @param string $s HTML string * @param string $class * @return void */ @@ -89,5 +89,4 @@ protected function output($s, $class = 'info') { echo "
    $s
    \n"; } - } diff --git a/tests/cases/integration/dbal/Runner.FirstRun.phpt b/tests/cases/integration/dbal/Runner.FirstRun.phpt index 2a565af..87e59ae 100644 --- a/tests/cases/integration/dbal/Runner.FirstRun.phpt +++ b/tests/cases/integration/dbal/Runner.FirstRun.phpt @@ -37,19 +37,19 @@ class FirstRunTest extends IntegrationTestCase Assert::same('001.sql', $migrations[0]->filename); Assert::type('string', $migrations[0]->checksum); - Assert::same(TRUE, $migrations[0]->completed); + Assert::same(true, $migrations[0]->completed); Assert::type('DateTime', $migrations[0]->executedAt); Assert::same('structures', $migrations[0]->group); Assert::same('002.sql', $migrations[1]->filename); Assert::type('string', $migrations[1]->checksum); - Assert::same(TRUE, $migrations[1]->completed); + Assert::same(true, $migrations[1]->completed); Assert::type('DateTime', $migrations[1]->executedAt); Assert::same('structures', $migrations[1]->group); Assert::same('003.sql', $migrations[2]->filename); Assert::type('string', $migrations[2]->checksum); - Assert::same(TRUE, $migrations[2]->completed); + Assert::same(true, $migrations[2]->completed); Assert::type('DateTime', $migrations[2]->executedAt); Assert::same('basic-data', $migrations[2]->group); } @@ -75,19 +75,19 @@ class FirstRunTest extends IntegrationTestCase Assert::same('001.sql', $migrations[0]->filename); Assert::type('string', $migrations[0]->checksum); - Assert::same(TRUE, $migrations[0]->completed); + Assert::same(true, $migrations[0]->completed); Assert::type('DateTime', $migrations[0]->executedAt); Assert::same('structures', $migrations[0]->group); Assert::same('002.sql', $migrations[1]->filename); Assert::type('string', $migrations[1]->checksum); - Assert::same(TRUE, $migrations[1]->completed); + Assert::same(true, $migrations[1]->completed); Assert::type('DateTime', $migrations[1]->executedAt); Assert::same('structures', $migrations[1]->group); Assert::same('003.sql', $migrations[2]->filename); Assert::type('string', $migrations[2]->checksum); - Assert::same(TRUE, $migrations[2]->completed); + Assert::same(true, $migrations[2]->completed); Assert::type('DateTime', $migrations[2]->executedAt); Assert::same('basic-data', $migrations[2]->group); } diff --git a/tests/cases/integration/nette-di/MigrationsExtension.phpt b/tests/cases/integration/nette-di/MigrationsExtension.phpt index 7e25add..2191506 100644 --- a/tests/cases/integration/nette-di/MigrationsExtension.phpt +++ b/tests/cases/integration/nette-di/MigrationsExtension.phpt @@ -115,9 +115,9 @@ class MigrationsExtensionTest extends TestCase * @param string $config * @return Nette\DI\Container */ - protected function createContainer($config, array $dynamicParameters = NULL) + protected function createContainer($config, array $dynamicParameters = null) { - $options = parse_ini_file(__DIR__ . '/../../../drivers.ini', TRUE)['mysql']; + $options = parse_ini_file(__DIR__ . '/../../../drivers.ini', true)['mysql']; $dibiConfig = [ 'host' => $options['host'], @@ -148,7 +148,7 @@ class MigrationsExtensionTest extends TestCase ] ]); $compiler->loadConfig(__DIR__ . "/MigrationsExtension.$config.neon"); - if ($dynamicParameters !== NULL) { + if ($dynamicParameters !== null) { $compiler->setDynamicParameterNames(array_keys($dynamicParameters)); } }, diff --git a/tests/cases/integration/symfony-bundle/SymfonyBundleTest.phpt b/tests/cases/integration/symfony-bundle/SymfonyBundleTest.phpt index 47b0ff2..157b9b4 100644 --- a/tests/cases/integration/symfony-bundle/SymfonyBundleTest.phpt +++ b/tests/cases/integration/symfony-bundle/SymfonyBundleTest.phpt @@ -31,7 +31,7 @@ class SymfonyBundleTest extends TestCase Environment::lock(__CLASS__, __DIR__ . '/../../../temp'); $options = Environment::loadData(); - $driversConfig = parse_ini_file(__DIR__ . '/../../../drivers.ini', TRUE); + $driversConfig = parse_ini_file(__DIR__ . '/../../../drivers.ini', true); $dbalOptions = $driversConfig[$options['driver']]; $doctrineDriver = $options['driver'] === 'mysql' ? 'pdo_mysql' : 'pdo_pgsql'; diff --git a/tests/cases/unit/BaseDriverTest.phpt b/tests/cases/unit/BaseDriverTest.phpt index 462e7bb..588e302 100644 --- a/tests/cases/unit/BaseDriverTest.phpt +++ b/tests/cases/unit/BaseDriverTest.phpt @@ -33,7 +33,7 @@ class BaseDriverTest extends Tester\TestCase $driver->loadFile(Tester\FileMock::create($content)); Mockery::close(); - Assert::true(TRUE); + Assert::true(true); } diff --git a/tests/cases/unit/Finder.logicalName.phpt b/tests/cases/unit/Finder.logicalName.phpt index c40ce0c..2b041c6 100644 --- a/tests/cases/unit/Finder.logicalName.phpt +++ b/tests/cases/unit/Finder.logicalName.phpt @@ -37,7 +37,7 @@ class FinderLogicalNameTest extends Tester\TestCase $group = new Group(); $group->dependencies = []; $group->directory = './baseDir/structures'; - $group->enabled = TRUE; + $group->enabled = true; $group->name = 'structures'; $this->groups = [$group]; } diff --git a/tests/cases/unit/OrderResolverTest.phpt b/tests/cases/unit/OrderResolverTest.phpt index 294017e..139c671 100644 --- a/tests/cases/unit/OrderResolverTest.phpt +++ b/tests/cases/unit/OrderResolverTest.phpt @@ -127,7 +127,7 @@ class OrderResolverTest extends Tester\TestCase $resolver = new OrderResolver; $groupA = $this->createGroup('structures'); - $groupB = $this->createGroup('data', FALSE); + $groupB = $this->createGroup('data', false); $migrationA = $this->createMigration($groupA->name, '1s'); $migrationB = $this->createMigration($groupB->name, '2d'); @@ -166,17 +166,17 @@ class OrderResolverTest extends Tester\TestCase public function testRunWithDisabledGroups() { $groupA = $this->createGroup('structures'); - $groupB = $this->createGroup('data', FALSE, ['structures']); - $groupC = $this->createGroup('test-data', FALSE, ['data']); + $groupB = $this->createGroup('data', false, ['structures']); + $groupC = $this->createGroup('test-data', false, ['data']); $method = new \ReflectionMethod('Nextras\Migrations\Engine\OrderResolver', 'validateGroups'); - $method->setAccessible(TRUE); + $method->setAccessible(true); $method->invoke(new OrderResolver, [ 'structures' => $groupA, 'data' => $groupB, 'test-data' => $groupC, ]); - Tester\Environment::$checkAssertions = FALSE; + Tester\Environment::$checkAssertions = false; } @@ -185,7 +185,7 @@ class OrderResolverTest extends Tester\TestCase $resolver = new OrderResolver(); $groupA = $this->createGroup('structures'); - $groupB = $this->createGroup('data', TRUE, ['structures']); + $groupB = $this->createGroup('data', true, ['structures']); $fileA = $this->createFile('foo', $groupA); $fileB = $this->createFile('foo', $groupB); @@ -226,8 +226,8 @@ class OrderResolverTest extends Tester\TestCase $resolver = new OrderResolver(); $groupA = $this->createGroup('a'); - $groupB = $this->createGroup('b', TRUE, ['a']); - $groupC = $this->createGroup('c', TRUE, ['a']); + $groupB = $this->createGroup('b', true, ['a']); + $groupC = $this->createGroup('c', true, ['a']); $migrationA = $this->createMigration($groupA->name, '1a'); $migrationC = $this->createMigration($groupC->name, '3c'); @@ -292,7 +292,7 @@ class OrderResolverTest extends Tester\TestCase $resolver = new OrderResolver; $groupA = $this->createGroup('structures'); - $migrationA = $this->createMigration($groupA->name, '1s', NULL, FALSE); + $migrationA = $this->createMigration($groupA->name, '1s', null, false); $fileA = $this->createFile('1s', $groupA); $fileB = $this->createFile('2s', $groupA); @@ -336,8 +336,8 @@ class OrderResolverTest extends Tester\TestCase $resolver = new OrderResolver(); $groupA = $this->createGroup('a'); - $groupB = $this->createGroup('b', TRUE, ['a']); - $groupC = $this->createGroup('c', TRUE, ['b']); + $groupB = $this->createGroup('b', true, ['a']); + $groupC = $this->createGroup('c', true, ['b']); $migrationA = $this->createMigration($groupA->name, '1a'); $migrationC = $this->createMigration($groupC->name, '3c'); @@ -363,7 +363,7 @@ class OrderResolverTest extends Tester\TestCase $resolver = new OrderResolver(); $groupA = $this->createGroup('a'); - $groupB = $this->createGroup('b', TRUE, ['a']); + $groupB = $this->createGroup('b', true, ['a']); $migrationA = $this->createMigration($groupB->name, '1b'); $migrationC = $this->createMigration($groupA->name, '3a'); @@ -405,7 +405,7 @@ class OrderResolverTest extends Tester\TestCase { $resolver = new OrderResolver; - $groupB = $this->createGroup('data', TRUE, ['structures']); + $groupB = $this->createGroup('data', true, ['structures']); Assert::exception(function () use ($resolver, $groupB) { $resolver->resolve( @@ -422,8 +422,8 @@ class OrderResolverTest extends Tester\TestCase { $resolver = new OrderResolver; - $groupA = $this->createGroup('structures', FALSE); - $groupB = $this->createGroup('data', TRUE, ['structures']); + $groupA = $this->createGroup('structures', false); + $groupB = $this->createGroup('data', true, ['structures']); Assert::exception(function () use ($resolver, $groupA, $groupB) { $resolver->resolve( @@ -461,8 +461,8 @@ class OrderResolverTest extends Tester\TestCase { $resolver = new OrderResolver(); - $groupA = $this->createGroup('structures', TRUE, ['data']); - $groupB = $this->createGroup('data', TRUE, ['structures']); + $groupA = $this->createGroup('structures', true, ['data']); + $groupB = $this->createGroup('data', true, ['structures']); $fileA = $this->createFile('foo', $groupA); $fileB = $this->createFile('foo', $groupB); @@ -478,7 +478,7 @@ class OrderResolverTest extends Tester\TestCase } - private function createMigration($groupName, $fileName, $checksum = NULL, $completed = TRUE) + private function createMigration($groupName, $fileName, $checksum = null, $completed = true) { $migration = new Migration; $migration->group = $groupName; @@ -489,7 +489,7 @@ class OrderResolverTest extends Tester\TestCase } - private function createFile($name, $group, $checksum = NULL) + private function createFile($name, $group, $checksum = null) { $file = new File; $file->name = $name; @@ -499,7 +499,7 @@ class OrderResolverTest extends Tester\TestCase } - private function createGroup($name, $enabled = TRUE, $deps = []) + private function createGroup($name, $enabled = true, $deps = []) { $group = new Group; $group->name = $name; diff --git a/tests/inc/IntegrationTestCase.php b/tests/inc/IntegrationTestCase.php index cf03f3f..aa7be79 100644 --- a/tests/inc/IntegrationTestCase.php +++ b/tests/inc/IntegrationTestCase.php @@ -45,7 +45,7 @@ protected function setUp() parent::setUp(); $options = Environment::loadData(); - $driversConfig = parse_ini_file(__DIR__ . '/../drivers.ini', TRUE); + $driversConfig = parse_ini_file(__DIR__ . '/../drivers.ini', true); $dbalOptions = $driversConfig[$options['driver']] + $options; $this->fixtureDir = __DIR__ . '/../fixtures/' . $options['driver']; @@ -84,19 +84,19 @@ protected function tearDown() protected function getGroups($dir) { $structures = new Group(); - $structures->enabled = TRUE; + $structures->enabled = true; $structures->name = 'structures'; $structures->directory = $dir . '/structures'; $structures->dependencies = []; $basicData = new Group(); - $basicData->enabled = TRUE; + $basicData->enabled = true; $basicData->name = 'basic-data'; $basicData->directory = $dir . '/basic-data'; $basicData->dependencies = ['structures']; $dummyData = new Group(); - $dummyData->enabled = TRUE; + $dummyData->enabled = true; $dummyData->name = 'dummy-data'; $dummyData->directory = $dir . '/dummy-data'; $dummyData->dependencies = ['structures', 'basic-data']; diff --git a/tests/inc/TestPrinter.php b/tests/inc/TestPrinter.php index b9760f7..64d2da1 100644 --- a/tests/inc/TestPrinter.php +++ b/tests/inc/TestPrinter.php @@ -17,7 +17,7 @@ class TestPrinter extends Console public function __construct() { parent::__construct(); - $this->useColors = FALSE; + $this->useColors = false; } diff --git a/tests/inc/TestSymfonyKernel.php b/tests/inc/TestSymfonyKernel.php index 8743880..126a39d 100644 --- a/tests/inc/TestSymfonyKernel.php +++ b/tests/inc/TestSymfonyKernel.php @@ -26,7 +26,7 @@ class TestSymfonyKernel extends Kernel */ public function __construct($configPath, array $parameters) { - parent::__construct('dev', TRUE); + parent::__construct('dev', true); $this->configPath = $configPath; $this->parameters = $parameters; diff --git a/tests/inc/TestSymfonyKernel6.php b/tests/inc/TestSymfonyKernel6.php index 8152e0e..0ffbf40 100644 --- a/tests/inc/TestSymfonyKernel6.php +++ b/tests/inc/TestSymfonyKernel6.php @@ -26,7 +26,7 @@ class TestSymfonyKernel6 extends Kernel */ public function __construct($configPath, array $parameters) { - parent::__construct('dev', TRUE); + parent::__construct('dev', true); $this->configPath = $configPath; $this->parameters = $parameters; From 43f0405571c11f38fecb9d37ad15e10ed856c736 Mon Sep 17 00:00:00 2001 From: Jan Tvrdik Date: Sat, 19 Dec 2020 14:50:19 +0100 Subject: [PATCH 09/12] add strict_types --- src/Bridges/Dibi/Dibi3Adapter.php | 2 +- src/Bridges/Dibi/DibiAdapter.php | 2 +- src/Bridges/DoctrineDbal/DoctrineAdapter.php | 2 +- src/Bridges/DoctrineOrm/StructureDiffGenerator.php | 2 +- src/Bridges/NetteDI/MigrationsExtension.php | 2 +- src/Bridges/NetteDatabase/NetteAdapter.php | 4 ++-- src/Bridges/NextrasDbal/NextrasAdapter.php | 2 +- src/Bridges/PsrLog/PsrLogPrinter.php | 2 +- .../SymfonyBundle/DependencyInjection/Configuration.php | 2 +- .../DependencyInjection/NextrasMigrationsExtension.php | 2 +- src/Bridges/SymfonyBundle/NextrasMigrationsBundle.php | 2 +- src/Bridges/SymfonyConsole/BaseCommand.php | 2 +- src/Bridges/SymfonyConsole/ContinueCommand.php | 2 +- src/Bridges/SymfonyConsole/CreateCommand.php | 2 +- src/Bridges/SymfonyConsole/ResetCommand.php | 2 +- src/Configurations/Configuration.php | 2 +- src/Configurations/DefaultConfiguration.php | 2 +- src/Controllers/BaseController.php | 2 +- src/Controllers/ConsoleController.php | 2 +- src/Controllers/HttpController.php | 2 +- src/Drivers/BaseDriver.php | 2 +- src/Drivers/MySqlDriver.php | 2 +- src/Drivers/PgSqlDriver.php | 2 +- src/Engine/Finder.php | 2 +- src/Engine/OrderResolver.php | 2 +- src/Engine/Runner.php | 2 +- src/Entities/File.php | 2 +- src/Entities/Group.php | 2 +- src/Entities/Migration.php | 2 +- src/Extensions/PhpHandler.php | 2 +- src/Extensions/SqlHandler.php | 2 +- src/IConfiguration.php | 2 +- src/IDbal.php | 2 +- src/IDiffGenerator.php | 2 +- src/IDriver.php | 2 +- src/IExtensionHandler.php | 2 +- src/IPrinter.php | 2 +- src/Printers/Console.php | 2 +- src/Printers/DevNull.php | 2 +- src/Printers/HtmlDump.php | 2 +- src/exceptions.php | 2 +- tests/bootstrap.php | 2 +- tests/cases/integration/dbal/Runner.EmptyRun.phpt | 2 +- tests/cases/integration/dbal/Runner.FirstRun.phpt | 2 +- tests/cases/integration/dbal/Runner.SecondRun.phpt | 2 +- tests/cases/integration/nette-di/MigrationsExtension.phpt | 2 +- tests/cases/integration/symfony-bundle/SymfonyBundleTest.phpt | 2 +- tests/cases/unit/BaseDriverTest.phpt | 2 +- tests/cases/unit/CreateCommandTest.phpt | 2 +- tests/cases/unit/Finder.logicalName.phpt | 2 +- tests/cases/unit/OrderResolverTest.phpt | 2 +- tests/fixtures/mysql/cleanup.php | 2 +- tests/fixtures/mysql/init.php | 2 +- tests/fixtures/pgsql/cleanup.php | 2 +- tests/fixtures/pgsql/init.php | 2 +- tests/inc/IntegrationTestCase.php | 2 +- tests/inc/TestPrinter.php | 2 +- tests/inc/TestSymfonyKernel.php | 2 +- tests/inc/TestSymfonyKernel6.php | 2 +- 59 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/Bridges/Dibi/Dibi3Adapter.php b/src/Bridges/Dibi/Dibi3Adapter.php index fa3fd0a..684c296 100644 --- a/src/Bridges/Dibi/Dibi3Adapter.php +++ b/src/Bridges/Dibi/Dibi3Adapter.php @@ -1,4 +1,4 @@ -conn->quote($value, PDO::PARAM_INT); + return $this->conn->quote((string) $value, PDO::PARAM_INT); } diff --git a/src/Bridges/NextrasDbal/NextrasAdapter.php b/src/Bridges/NextrasDbal/NextrasAdapter.php index 8dade0b..ebb5912 100644 --- a/src/Bridges/NextrasDbal/NextrasAdapter.php +++ b/src/Bridges/NextrasDbal/NextrasAdapter.php @@ -1,4 +1,4 @@ -dbal->exec('DROP DATABASE IF EXISTS ' . $this->dbal->escapeIdentifier($this->dbName)); diff --git a/tests/fixtures/mysql/init.php b/tests/fixtures/mysql/init.php index 2196258..694111e 100644 --- a/tests/fixtures/mysql/init.php +++ b/tests/fixtures/mysql/init.php @@ -1,4 +1,4 @@ -dbal->escapeIdentifier($this->dbName); diff --git a/tests/fixtures/pgsql/cleanup.php b/tests/fixtures/pgsql/cleanup.php index 775c7c0..21e15bb 100644 --- a/tests/fixtures/pgsql/cleanup.php +++ b/tests/fixtures/pgsql/cleanup.php @@ -1,4 +1,4 @@ -dbal->escapeIdentifier($this->dbName); diff --git a/tests/fixtures/pgsql/init.php b/tests/fixtures/pgsql/init.php index 8e9460a..07bdd3c 100644 --- a/tests/fixtures/pgsql/init.php +++ b/tests/fixtures/pgsql/init.php @@ -1,4 +1,4 @@ -dbal->escapeIdentifier($this->dbName); diff --git a/tests/inc/IntegrationTestCase.php b/tests/inc/IntegrationTestCase.php index aa7be79..5d2e420 100644 --- a/tests/inc/IntegrationTestCase.php +++ b/tests/inc/IntegrationTestCase.php @@ -1,4 +1,4 @@ - Date: Sun, 20 Dec 2020 16:22:25 +0100 Subject: [PATCH 10/12] use ::class syntax --- src/Bridges/NetteDI/MigrationsExtension.php | 64 ++++++++++--------- .../NextrasMigrationsExtension.php | 39 +++++------ src/Bridges/SymfonyConsole/CreateCommand.php | 7 +- .../integration/dbal/Runner.EmptyRun.phpt | 2 - .../integration/dbal/Runner.FirstRun.phpt | 1 - .../integration/dbal/Runner.SecondRun.phpt | 4 +- .../nette-di/MigrationsExtension.phpt | 14 ++-- tests/cases/unit/BaseDriverTest.phpt | 5 +- tests/cases/unit/CreateCommandTest.phpt | 3 +- tests/cases/unit/Finder.logicalName.phpt | 3 +- tests/cases/unit/OrderResolverTest.phpt | 25 ++++---- 11 files changed, 87 insertions(+), 80 deletions(-) diff --git a/src/Bridges/NetteDI/MigrationsExtension.php b/src/Bridges/NetteDI/MigrationsExtension.php index 0c2d480..931dad2 100644 --- a/src/Bridges/NetteDI/MigrationsExtension.php +++ b/src/Bridges/NetteDI/MigrationsExtension.php @@ -10,11 +10,13 @@ namespace Nextras\Migrations\Bridges\NetteDI; use Doctrine; +use Dibi; use Nette; use Nette\DI\ContainerBuilder; use Nette\Utils\Strings; use Nette\Utils\Validators; use Nextras; +use Symfony; class MigrationsExtension extends Nette\DI\CompilerExtension @@ -40,24 +42,24 @@ class MigrationsExtension extends Nette\DI\CompilerExtension /** @var array */ protected $dbals = [ - 'dibi' => 'Nextras\Migrations\Bridges\Dibi\DibiAdapter', - 'dibi3' => 'Nextras\Migrations\Bridges\Dibi\Dibi3Adapter', - 'dibi4' => 'Nextras\Migrations\Bridges\Dibi\Dibi3Adapter', - 'doctrine' => 'Nextras\Migrations\Bridges\DoctrineDbal\DoctrineAdapter', - 'nette' => 'Nextras\Migrations\Bridges\NetteDatabase\NetteAdapter', - 'nextras' => 'Nextras\Migrations\Bridges\NextrasDbal\NextrasAdapter', + 'dibi' => Nextras\Migrations\Bridges\Dibi\DibiAdapter::class, + 'dibi3' => Nextras\Migrations\Bridges\Dibi\Dibi3Adapter::class, + 'dibi4' => Nextras\Migrations\Bridges\Dibi\Dibi3Adapter::class, + 'doctrine' => Nextras\Migrations\Bridges\DoctrineDbal\DoctrineAdapter::class, + 'nette' => Nextras\Migrations\Bridges\NetteDatabase\NetteAdapter::class, + 'nextras' => Nextras\Migrations\Bridges\NextrasDbal\NextrasAdapter::class, ]; /** @var array */ protected $drivers = [ - 'mysql' => 'Nextras\Migrations\Drivers\MySqlDriver', - 'pgsql' => 'Nextras\Migrations\Drivers\PgSqlDriver', + 'mysql' => Nextras\Migrations\Drivers\MySqlDriver::class, + 'pgsql' => Nextras\Migrations\Drivers\PgSqlDriver::class, ]; /** @var array */ protected $printers = [ - 'console' => 'Nextras\Migrations\Printers\Console', - 'psrLog' => 'Nextras\Migrations\Bridges\PsrLog\PsrLogPrinter', + 'console' => Nextras\Migrations\Printers\Console::class, + 'psrLog' => Nextras\Migrations\Bridges\PsrLog\PsrLogPrinter::class, ]; @@ -101,7 +103,7 @@ public function loadConfiguration() $configuration = $this->createConfigurationDefinition(); // commands - if (class_exists('Symfony\Component\Console\Command\Command')) { + if (class_exists(Symfony\Component\Console\Command\Command::class)) { $this->createSymfonyCommandDefinitions($driver, $configuration, $printer); } } @@ -113,13 +115,13 @@ public function beforeCompile() $config = $this->validateConfig($this->defaults); // dbal - foreach ($builder->findByType('Nextras\Migrations\IDbal') as $def) { + foreach ($builder->findByType(Nextras\Migrations\IDbal::class) as $def) { $factory = $def->getFactory(); - if ($factory->getEntity() !== 'Nextras\Migrations\Bridges\Dibi\DibiAdapter') { + if ($factory->getEntity() !== Nextras\Migrations\Bridges\Dibi\DibiAdapter::class) { continue; } - $conn = $builder->getByType('Dibi\Connection'); + $conn = $builder->getByType(Dibi\Connection::class); if (!$conn) { continue; } @@ -129,7 +131,7 @@ public function beforeCompile() // diff generator if ($config['diffGenerator'] === true) { - if ($builder->findByType('Doctrine\ORM\EntityManagerInterface') && $builder->hasDefinition($this->prefix('group.structures'))) { + if ($builder->findByType(Doctrine\ORM\EntityManagerInterface::class) && $builder->hasDefinition($this->prefix('group.structures'))) { Validators::assertField($config, 'ignoredQueriesFile', 'null|string'); $diffGenerator = $this->createDoctrineStructureDiffGeneratorDefinition($config['ignoredQueriesFile']); $builder->getDefinition($this->prefix('group.structures')) @@ -165,7 +167,7 @@ private function getDbalDefinition($dbal) if ($factory) { return $this->getContainerBuilder() ->addDefinition($this->prefix('dbal')) - ->setClass('Nextras\Migrations\IDbal') + ->setClass(Nextras\Migrations\IDbal::class) ->setFactory($factory); } elseif ($dbal === null) { @@ -201,7 +203,7 @@ private function getDriverDefinition($driver, $dbal) if ($factory) { return $this->getContainerBuilder() ->addDefinition($this->prefix('driver')) - ->setClass('Nextras\Migrations\IDriver') + ->setClass(Nextras\Migrations\IDriver::class) ->setFactory($factory); } elseif ($driver === null) { @@ -234,7 +236,7 @@ private function getPrinterDefinition($printer) if ($factory) { return $this->getContainerBuilder() ->addDefinition($this->prefix('printer')) - ->setClass('Nextras\Migrations\IPrinter') + ->setClass(Nextras\Migrations\IPrinter::class) ->setFactory($factory); } elseif ($printer === null) { @@ -320,7 +322,7 @@ private function createGroupDefinitions(array $groups) $groupDefinitions[] = $builder->addDefinition($this->prefix("group.$serviceName")) ->addTag(self::TAG_GROUP, ['for' => [$this->name]]) ->setAutowired(false) - ->setClass('Nextras\Migrations\Entities\Group') + ->setClass(Nextras\Migrations\Entities\Group::class) ->addSetup('$name', [$groupName]) ->addSetup('$enabled', [$enabled]) ->addSetup('$directory', [$directory]) @@ -339,12 +341,12 @@ private function createExtensionHandlerDefinitions($driver, $phpParams) $sqlHandler = $builder->addDefinition($this->prefix('extensionHandler.sql')) ->addTag(self::TAG_EXTENSION_HANDLER, ['for' => [$this->name], 'extension' => 'sql']) ->setAutowired(false) - ->setClass('Nextras\Migrations\Extensions\SqlHandler') + ->setClass(Nextras\Migrations\Extensions\SqlHandler::class) ->setArguments([$driver]); $phpHandler = $builder->addDefinition($this->prefix('extensionHandler.php')) ->addTag(self::TAG_EXTENSION_HANDLER, ['for' => [$this->name], 'extension' => 'php']) - ->setClass('Nextras\Migrations\Extensions\PhpHandler') + ->setClass(Nextras\Migrations\Extensions\PhpHandler::class) ->setAutowired(false) ->setArguments([$phpParams]); @@ -356,8 +358,8 @@ private function createConfigurationDefinition() { return $this->getContainerBuilder() ->addDefinition($this->prefix('configuration')) - ->setClass('Nextras\Migrations\IConfiguration') - ->setFactory('Nextras\Migrations\Configurations\Configuration'); + ->setClass(Nextras\Migrations\IConfiguration::class) + ->setFactory(Nextras\Migrations\Configurations\Configuration::class); } @@ -367,8 +369,8 @@ private function createDoctrineStructureDiffGeneratorDefinition($ignoredQueriesF return $builder->addDefinition($this->prefix('diffGenerator.structures')) ->setAutowired(false) - ->setClass('Nextras\Migrations\IDiffGenerator') - ->setFactory('Nextras\Migrations\Bridges\DoctrineOrm\StructureDiffGenerator') + ->setClass(Nextras\Migrations\IDiffGenerator::class) + ->setFactory(Nextras\Migrations\Bridges\DoctrineOrm\StructureDiffGenerator::class) ->setArguments(['@Doctrine\ORM\EntityManagerInterface', $ignoredQueriesFile]); } @@ -376,20 +378,20 @@ private function createDoctrineStructureDiffGeneratorDefinition($ignoredQueriesF private function createSymfonyCommandDefinitions($driver, $configuration, $printer) { $builder = $this->getContainerBuilder(); - $builder->addExcludedClasses(['Nextras\Migrations\Bridges\SymfonyConsole\BaseCommand']); + $builder->addExcludedClasses([Nextras\Migrations\Bridges\SymfonyConsole\BaseCommand::class]); $builder->addDefinition($this->prefix('continueCommand')) - ->setClass('Nextras\Migrations\Bridges\SymfonyConsole\ContinueCommand') + ->setClass(Nextras\Migrations\Bridges\SymfonyConsole\ContinueCommand::class) ->setArguments([$driver, $configuration, $printer]) ->addTag('kdyby.console.command'); $builder->addDefinition($this->prefix('createCommand')) - ->setClass('Nextras\Migrations\Bridges\SymfonyConsole\CreateCommand') + ->setClass(Nextras\Migrations\Bridges\SymfonyConsole\CreateCommand::class) ->setArguments([$driver, $configuration, $printer]) ->addTag('kdyby.console.command'); $builder->addDefinition($this->prefix('resetCommand')) - ->setClass('Nextras\Migrations\Bridges\SymfonyConsole\ResetCommand') + ->setClass(Nextras\Migrations\Bridges\SymfonyConsole\ResetCommand::class) ->setArguments([$driver, $configuration, $printer]) ->addTag('kdyby.console.command'); } @@ -397,10 +399,10 @@ private function createSymfonyCommandDefinitions($driver, $configuration, $print private function filterArguments(array $arguments) { - if (method_exists('Nette\DI\Helpers', 'filterArguments')) { + if (method_exists(Nette\DI\Helpers::class, 'filterArguments')) { return Nette\DI\Helpers::filterArguments($arguments); - } elseif (method_exists('Nette\DI\Compiler', 'filterArguments')) { + } elseif (method_exists(Nette\DI\Compiler::class, 'filterArguments')) { return Nette\DI\Compiler::filterArguments($arguments); } else { diff --git a/src/Bridges/SymfonyBundle/DependencyInjection/NextrasMigrationsExtension.php b/src/Bridges/SymfonyBundle/DependencyInjection/NextrasMigrationsExtension.php index 3c22938..d8192c0 100644 --- a/src/Bridges/SymfonyBundle/DependencyInjection/NextrasMigrationsExtension.php +++ b/src/Bridges/SymfonyBundle/DependencyInjection/NextrasMigrationsExtension.php @@ -9,6 +9,7 @@ namespace Nextras\Migrations\Bridges\SymfonyBundle\DependencyInjection; +use Nextras; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\HttpKernel\DependencyInjection\Extension; @@ -18,24 +19,24 @@ class NextrasMigrationsExtension extends Extension { /** @var array */ protected $dbals = [ - 'dibi' => 'Nextras\Migrations\Bridges\Dibi\DibiAdapter', - 'dibi3' => 'Nextras\Migrations\Bridges\Dibi\Dibi3Adapter', - 'dibi4' => 'Nextras\Migrations\Bridges\Dibi\Dibi3Adapter', - 'doctrine' => 'Nextras\Migrations\Bridges\DoctrineDbal\DoctrineAdapter', - 'nette' => 'Nextras\Migrations\Bridges\NetteDatabase\NetteAdapter', - 'nextras' => 'Nextras\Migrations\Bridges\NextrasDbal\NextrasAdapter', + 'dibi' => Nextras\Migrations\Bridges\Dibi\DibiAdapter::class, + 'dibi3' => Nextras\Migrations\Bridges\Dibi\Dibi3Adapter::class, + 'dibi4' => Nextras\Migrations\Bridges\Dibi\Dibi3Adapter::class, + 'doctrine' => Nextras\Migrations\Bridges\DoctrineDbal\DoctrineAdapter::class, + 'nette' => Nextras\Migrations\Bridges\NetteDatabase\NetteAdapter::class, + 'nextras' => Nextras\Migrations\Bridges\NextrasDbal\NextrasAdapter::class, ]; /** @var array */ protected $drivers = [ - 'mysql' => 'Nextras\Migrations\Drivers\MySqlDriver', - 'pgsql' => 'Nextras\Migrations\Drivers\PgSqlDriver', + 'mysql' => Nextras\Migrations\Drivers\MySqlDriver::class, + 'pgsql' => Nextras\Migrations\Drivers\PgSqlDriver::class, ]; /** @var array */ protected $printers = [ - 'console' => 'Nextras\Migrations\Printers\Console', - 'psrLog' => 'Nextras\Migrations\Bridges\PsrLog\PsrLogPrinter', + 'console' => Nextras\Migrations\Printers\Console::class, + 'psrLog' => Nextras\Migrations\Bridges\PsrLog\PsrLogPrinter::class, ]; @@ -62,13 +63,13 @@ public function load(array $configs, ContainerBuilder $container) ]); $container->addAliases([ - 'Nextras\Migrations\IDbal' => 'nextras_migrations.dbal', - 'Nextras\Migrations\IDriver' => 'nextras_migrations.driver', - 'Nextras\Migrations\IPrinter' => 'nextras_migrations.printer', + Nextras\Migrations\IDbal::class => 'nextras_migrations.dbal', + Nextras\Migrations\IDriver::class => 'nextras_migrations.driver', + Nextras\Migrations\IPrinter::class => 'nextras_migrations.printer', ]); if ($config['diff_generator'] === 'doctrine') { - $structureDiffGeneratorDefinition = new Definition('Nextras\Migrations\Bridges\DoctrineOrm\StructureDiffGenerator'); + $structureDiffGeneratorDefinition = new Definition(Nextras\Migrations\Bridges\DoctrineOrm\StructureDiffGenerator::class); $structureDiffGeneratorDefinition->setAutowired(true); $structureDiffGeneratorDefinition->setArgument('$ignoredQueriesFile', $config['ignored_queries_file']); @@ -83,19 +84,19 @@ public function load(array $configs, ContainerBuilder $container) } } - $configurationDefinition = new Definition('Nextras\Migrations\Configurations\DefaultConfiguration'); + $configurationDefinition = new Definition(Nextras\Migrations\Configurations\DefaultConfiguration::class); $configurationDefinition->setArguments([$config['dir'], $driverDefinition, $config['with_dummy_data'], $config['php_params']]); $configurationDefinition->addMethodCall('setStructureDiffGenerator', [$structureDiffGeneratorDefinition]); - $continueCommandDefinition = new Definition('Nextras\Migrations\Bridges\SymfonyConsole\ContinueCommand'); + $continueCommandDefinition = new Definition(Nextras\Migrations\Bridges\SymfonyConsole\ContinueCommand::class); $continueCommandDefinition->setArguments([$driverDefinition, $configurationDefinition, $printerDefinition]); $continueCommandDefinition->addTag('console.command'); - $createCommandDefinition = new Definition('Nextras\Migrations\Bridges\SymfonyConsole\CreateCommand'); + $createCommandDefinition = new Definition(Nextras\Migrations\Bridges\SymfonyConsole\CreateCommand::class); $createCommandDefinition->setArguments([$driverDefinition, $configurationDefinition, $printerDefinition]); $createCommandDefinition->addTag('console.command'); - $resetCommandDefinition = new Definition('Nextras\Migrations\Bridges\SymfonyConsole\ResetCommand'); + $resetCommandDefinition = new Definition(Nextras\Migrations\Bridges\SymfonyConsole\ResetCommand::class); $resetCommandDefinition->setArguments([$driverDefinition, $configurationDefinition, $printerDefinition]); $resetCommandDefinition->addTag('console.command'); @@ -107,7 +108,7 @@ public function load(array $configs, ContainerBuilder $container) ]); $container->addAliases([ - 'Nextras\Migrations\IConfiguration' => 'nextras_migrations.configuration', + Nextras\Migrations\IConfiguration::class => 'nextras_migrations.configuration', ]); if ($structureDiffGeneratorDefinition) { diff --git a/src/Bridges/SymfonyConsole/CreateCommand.php b/src/Bridges/SymfonyConsole/CreateCommand.php index fe735ad..de1294d 100644 --- a/src/Bridges/SymfonyConsole/CreateCommand.php +++ b/src/Bridges/SymfonyConsole/CreateCommand.php @@ -17,6 +17,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\String\Slugger\AsciiSlugger; +use Symfony\Contracts\Translation\LocaleAwareInterface; class CreateCommand extends BaseCommand @@ -152,12 +153,12 @@ protected function getFileName($label, $extension) if (preg_match('#^[a-z0-9.-]++$#i', $label)) { $slug = strtolower($label); - } elseif (class_exists('Nette\Utils\Strings')) { + } elseif (class_exists(Strings::class)) { $slug = Strings::webalize($label, '.'); } elseif ( - interface_exists('Symfony\Contracts\Translation\LocaleAwareInterface') && - class_exists('Symfony\Component\String\Slugger\AsciiSlugger') + interface_exists(LocaleAwareInterface::class) && + class_exists(AsciiSlugger::class) ) { $slugger = new AsciiSlugger('en'); $slug = $slugger->slug($label)->toString(); diff --git a/tests/cases/integration/dbal/Runner.EmptyRun.phpt b/tests/cases/integration/dbal/Runner.EmptyRun.phpt index 44c89be..5bc1c7e 100644 --- a/tests/cases/integration/dbal/Runner.EmptyRun.phpt +++ b/tests/cases/integration/dbal/Runner.EmptyRun.phpt @@ -7,9 +7,7 @@ namespace NextrasTests\Migrations; -use Mockery; use Nextras\Migrations\Engine\Runner; -use Tester; use Tester\Assert; require __DIR__ . '/../../../bootstrap.php'; diff --git a/tests/cases/integration/dbal/Runner.FirstRun.phpt b/tests/cases/integration/dbal/Runner.FirstRun.phpt index e841e99..2051f11 100644 --- a/tests/cases/integration/dbal/Runner.FirstRun.phpt +++ b/tests/cases/integration/dbal/Runner.FirstRun.phpt @@ -7,7 +7,6 @@ namespace NextrasTests\Migrations; -use Mockery; use Nextras\Migrations\Engine\Runner; use Tester; use Tester\Assert; diff --git a/tests/cases/integration/dbal/Runner.SecondRun.phpt b/tests/cases/integration/dbal/Runner.SecondRun.phpt index 088f8ae..0756b62 100644 --- a/tests/cases/integration/dbal/Runner.SecondRun.phpt +++ b/tests/cases/integration/dbal/Runner.SecondRun.phpt @@ -7,7 +7,7 @@ namespace NextrasTests\Migrations; -use Mockery; +use Nextras; use Nextras\Migrations\Engine\Runner; use Tester; use Tester\Assert; @@ -65,7 +65,7 @@ class SecondRunTest extends IntegrationTestCase Assert::throws(function () { $this->runner->run(Runner::MODE_CONTINUE); - }, 'Nextras\Migrations\LogicException'); + }, Nextras\Migrations\LogicException::class); Assert::same([ 'Nextras Migrations', diff --git a/tests/cases/integration/nette-di/MigrationsExtension.phpt b/tests/cases/integration/nette-di/MigrationsExtension.phpt index de9e297..0167527 100644 --- a/tests/cases/integration/nette-di/MigrationsExtension.phpt +++ b/tests/cases/integration/nette-di/MigrationsExtension.phpt @@ -7,6 +7,8 @@ namespace NextrasTests\Migrations; use Nette; +use Nextras; +use Symfony; use Tester\Assert; use Tester\Environment; use Tester\TestCase; @@ -23,8 +25,8 @@ class MigrationsExtensionTest extends TestCase { $dic = $this->createContainer($config); - Assert::type('Nextras\Migrations\Drivers\MySqlDriver', $dic->getByType('Nextras\Migrations\IDriver')); - Assert::count(3, $dic->findByType('Symfony\Component\Console\Command\Command')); + Assert::type(Nextras\Migrations\Drivers\MySqlDriver::class, $dic->getByType(Nextras\Migrations\IDriver::class)); + Assert::count(3, $dic->findByType(Symfony\Component\Console\Command\Command::class)); Assert::count(3, $dic->findByTag('kdyby.console.command')); } @@ -49,12 +51,12 @@ class MigrationsExtensionTest extends TestCase { $dic = $this->createContainer($config); - $configuration = $dic->getByType('Nextras\Migrations\IConfiguration'); - Assert::type('Nextras\Migrations\Configurations\Configuration', $configuration); + $configuration = $dic->getByType(Nextras\Migrations\IConfiguration::class); + Assert::type(Nextras\Migrations\Configurations\Configuration::class, $configuration); $groups = $configuration->getGroups(); Assert::count(3, $groups); - Assert::type('Nextras\Migrations\Bridges\DoctrineOrm\StructureDiffGenerator', $groups[0]->generator); + Assert::type(Nextras\Migrations\Bridges\DoctrineOrm\StructureDiffGenerator::class, $groups[0]->generator); Assert::null($groups[1]->generator); Assert::null($groups[2]->generator); } @@ -71,7 +73,7 @@ class MigrationsExtensionTest extends TestCase public function testDynamicContainerParameters() { - if (!method_exists('Nette\DI\Compiler', 'setDynamicParameterNames')) { + if (!method_exists(Nette\DI\Compiler::class, 'setDynamicParameterNames')) { Environment::skip('Required Nette >= 2.4.7'); } diff --git a/tests/cases/unit/BaseDriverTest.phpt b/tests/cases/unit/BaseDriverTest.phpt index 8ed2178..3ebfa19 100644 --- a/tests/cases/unit/BaseDriverTest.phpt +++ b/tests/cases/unit/BaseDriverTest.phpt @@ -7,6 +7,7 @@ namespace NextrasTests\Migrations; use Mockery; +use Nextras; use Tester; use Tester\Assert; @@ -20,10 +21,10 @@ class BaseDriverTest extends Tester\TestCase */ public function testLoadFile($content, array $expectedQueries) { - $dbal = Mockery::mock('Nextras\Migrations\IDbal'); + $dbal = Mockery::mock(Nextras\Migrations\IDbal::class); $dbal->shouldReceive('escapeIdentifier')->with('migrations')->andReturn('migrations'); - $driver = Mockery::mock('Nextras\Migrations\Drivers\BaseDriver', array($dbal)); + $driver = Mockery::mock(Nextras\Migrations\Drivers\BaseDriver::class, array($dbal)); $driver->shouldDeferMissing(); foreach ($expectedQueries as $expectedQuery) { diff --git a/tests/cases/unit/CreateCommandTest.phpt b/tests/cases/unit/CreateCommandTest.phpt index ac998fc..cb3da98 100644 --- a/tests/cases/unit/CreateCommandTest.phpt +++ b/tests/cases/unit/CreateCommandTest.phpt @@ -6,6 +6,7 @@ namespace NextrasTests\Migrations\Bridges\SymfonyConsole; +use Nextras; use Nextras\Migrations\Bridges\SymfonyConsole\CreateCommand; use Nextras\Migrations\Configurations\DefaultConfiguration; use Mockery; @@ -19,7 +20,7 @@ class CreateCommandTest extends Tester\TestCase { public function testTypeArgDescription() { - $driver = Mockery::mock('Nextras\Migrations\IDriver'); + $driver = Mockery::mock(Nextras\Migrations\IDriver::class); $config = new DefaultConfiguration('migrations', $driver); $command = new CreateCommand($driver, $config); diff --git a/tests/cases/unit/Finder.logicalName.phpt b/tests/cases/unit/Finder.logicalName.phpt index 985a28c..fcf1c9d 100644 --- a/tests/cases/unit/Finder.logicalName.phpt +++ b/tests/cases/unit/Finder.logicalName.phpt @@ -7,6 +7,7 @@ namespace NextrasTests\Migrations; use Mockery; +use Nextras; use Nextras\Migrations\Engine\Finder; use Nextras\Migrations\Entities\Group; use Tester; @@ -28,7 +29,7 @@ class FinderLogicalNameTest extends Tester\TestCase protected function setUp() { parent::setUp(); - $this->finder = Mockery::mock('Nextras\Migrations\Engine\Finder') + $this->finder = Mockery::mock(Nextras\Migrations\Engine\Finder::class) ->shouldAllowMockingProtectedMethods() ->shouldDeferMissing() ->shouldReceive('getChecksum') diff --git a/tests/cases/unit/OrderResolverTest.phpt b/tests/cases/unit/OrderResolverTest.phpt index 764fb40..619b6b4 100644 --- a/tests/cases/unit/OrderResolverTest.phpt +++ b/tests/cases/unit/OrderResolverTest.phpt @@ -6,6 +6,7 @@ namespace NextrasTests\Migrations; +use Nextras; use Nextras\Migrations\Engine\OrderResolver; use Nextras\Migrations\Engine\Runner; use Nextras\Migrations\Entities\Group; @@ -169,7 +170,7 @@ class OrderResolverTest extends Tester\TestCase $groupB = $this->createGroup('data', false, ['structures']); $groupC = $this->createGroup('test-data', false, ['data']); - $method = new \ReflectionMethod('Nextras\Migrations\Engine\OrderResolver', 'validateGroups'); + $method = new \ReflectionMethod(Nextras\Migrations\Engine\OrderResolver::class, 'validateGroups'); $method->setAccessible(true); $method->invoke(new OrderResolver, [ 'structures' => $groupA, @@ -262,7 +263,7 @@ class OrderResolverTest extends Tester\TestCase [$fileB], Runner::MODE_CONTINUE ); - }, 'Nextras\Migrations\LogicException', 'Previously executed migration "structures/1s" is missing.'); + }, Nextras\Migrations\LogicException::class, 'Previously executed migration "structures/1s" is missing.'); } @@ -283,7 +284,7 @@ class OrderResolverTest extends Tester\TestCase [$fileB, $fileA], Runner::MODE_CONTINUE ); - }, 'Nextras\Migrations\LogicException', 'Previously executed migration "structures/1s" has been changed. File checksum is "1s.md5.Y", but executed migration had checksum "1s.md5.X".'); + }, Nextras\Migrations\LogicException::class, 'Previously executed migration "structures/1s" has been changed. File checksum is "1s.md5.Y", but executed migration had checksum "1s.md5.X".'); } @@ -304,7 +305,7 @@ class OrderResolverTest extends Tester\TestCase [$fileB, $fileA], Runner::MODE_CONTINUE ); - }, 'Nextras\Migrations\LogicException', 'Previously executed migration "structures/1s" did not succeed. Please fix this manually or reset the migrations.'); + }, Nextras\Migrations\LogicException::class, 'Previously executed migration "structures/1s" did not succeed. Please fix this manually or reset the migrations.'); } @@ -327,7 +328,7 @@ class OrderResolverTest extends Tester\TestCase [$fileA, $fileB, $fileC], Runner::MODE_CONTINUE ); - }, 'Nextras\Migrations\LogicException', 'New migration "structures/2s" must follow after the latest executed migration "structures/3s".'); + }, Nextras\Migrations\LogicException::class, 'New migration "structures/2s" must follow after the latest executed migration "structures/3s".'); } @@ -354,7 +355,7 @@ class OrderResolverTest extends Tester\TestCase [$fileA, $fileB, $fileC], Runner::MODE_CONTINUE ); - }, 'Nextras\Migrations\LogicException', 'New migration "b/2b" must follow after the latest executed migration "c/3c".'); + }, Nextras\Migrations\LogicException::class, 'New migration "b/2b" must follow after the latest executed migration "c/3c".'); } @@ -380,7 +381,7 @@ class OrderResolverTest extends Tester\TestCase [$fileA, $fileB, $fileC], Runner::MODE_CONTINUE ); - }, 'Nextras\Migrations\LogicException', 'New migration "b/2b" must follow after the latest executed migration "a/3a".'); + }, Nextras\Migrations\LogicException::class, 'New migration "b/2b" must follow after the latest executed migration "a/3a".'); } @@ -397,7 +398,7 @@ class OrderResolverTest extends Tester\TestCase [], Runner::MODE_CONTINUE ); - }, 'Nextras\Migrations\LogicException', 'Existing migrations depend on unknown group "foo".'); + }, Nextras\Migrations\LogicException::class, 'Existing migrations depend on unknown group "foo".'); } @@ -414,7 +415,7 @@ class OrderResolverTest extends Tester\TestCase [], Runner::MODE_CONTINUE ); - }, 'Nextras\Migrations\LogicException', 'Group "data" depends on unknown group "structures".'); + }, Nextras\Migrations\LogicException::class, 'Group "data" depends on unknown group "structures".'); } @@ -432,7 +433,7 @@ class OrderResolverTest extends Tester\TestCase [], Runner::MODE_CONTINUE ); - }, 'Nextras\Migrations\LogicException', 'Group "data" depends on disabled group "structures". Please enable group "structures" to continue.'); + }, Nextras\Migrations\LogicException::class, 'Group "data" depends on disabled group "structures". Please enable group "structures" to continue.'); } @@ -453,7 +454,7 @@ class OrderResolverTest extends Tester\TestCase [$fileA, $fileB], Runner::MODE_CONTINUE ); - }, 'Nextras\Migrations\LogicException', 'Unable to determine order for migrations "data/foo" and "structures/foo".'); + }, Nextras\Migrations\LogicException::class, 'Unable to determine order for migrations "data/foo" and "structures/foo".'); } @@ -474,7 +475,7 @@ class OrderResolverTest extends Tester\TestCase [$fileA, $fileB], Runner::MODE_CONTINUE ); - }, 'Nextras\Migrations\LogicException', 'Unable to determine order for migrations "data/foo" and "structures/foo".'); + }, Nextras\Migrations\LogicException::class, 'Unable to determine order for migrations "data/foo" and "structures/foo".'); } From 03a2891e4c9c9b3a8af38451b9159c25d9bb9be7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Tvrd=C3=ADk?= Date: Tue, 9 Jan 2024 20:42:31 +0100 Subject: [PATCH 11/12] use PHP 7.1 types --- src/Bridges/Dibi/Dibi3Adapter.php | 23 ++--- src/Bridges/Dibi/DibiAdapter.php | 19 +++-- src/Bridges/DoctrineDbal/DoctrineAdapter.php | 16 ++-- .../DoctrineOrm/StructureDiffGenerator.php | 24 ++---- src/Bridges/NetteDI/MigrationsExtension.php | 84 ++++++++++++++----- src/Bridges/NetteDatabase/NetteAdapter.php | 16 ++-- src/Bridges/NextrasDbal/NextrasAdapter.php | 16 ++-- src/Bridges/PsrLog/PsrLogPrinter.php | 12 +-- .../DependencyInjection/Configuration.php | 2 +- .../NextrasMigrationsExtension.php | 8 +- src/Bridges/SymfonyConsole/BaseCommand.php | 15 +--- .../SymfonyConsole/ContinueCommand.php | 5 +- src/Bridges/SymfonyConsole/CreateCommand.php | 71 +++------------- src/Bridges/SymfonyConsole/ResetCommand.php | 4 +- src/Configurations/Configuration.php | 18 ++-- src/Configurations/DefaultConfiguration.php | 39 +++------ src/Controllers/BaseController.php | 24 ++++-- src/Controllers/ConsoleController.php | 9 +- src/Controllers/HttpController.php | 24 +++--- src/Drivers/BaseDriver.php | 15 +--- src/Drivers/MySqlDriver.php | 31 +++---- src/Drivers/PgSqlDriver.php | 35 ++++---- src/Engine/Finder.php | 33 +++----- src/Engine/OrderResolver.php | 75 +++++++++++------ src/Engine/Runner.php | 30 +++---- src/Entities/Group.php | 2 +- src/Extensions/PhpHandler.php | 20 ++--- src/Extensions/SqlHandler.php | 11 +-- src/IConfiguration.php | 8 +- src/IDbal.php | 41 ++------- src/IDiffGenerator.php | 7 +- src/IDriver.php | 50 ++++------- src/IExtensionHandler.php | 3 +- src/IPrinter.php | 27 ++---- src/Printers/Console.php | 50 ++++------- src/Printers/DevNull.php | 12 +-- src/Printers/HtmlDump.php | 21 ++--- src/exceptions.php | 4 +- .../integration/dbal/Runner.EmptyRun.phpt | 4 +- .../integration/dbal/Runner.FirstRun.phpt | 6 +- .../integration/dbal/Runner.SecondRun.phpt | 8 +- .../nette-di/MigrationsExtension.phpt | 20 ++--- .../symfony-bundle/SymfonyBundleTest.phpt | 6 +- tests/cases/unit/BaseDriverTest.phpt | 4 +- tests/cases/unit/CreateCommandTest.phpt | 2 +- tests/cases/unit/Finder.logicalName.phpt | 8 +- tests/cases/unit/OrderResolverTest.phpt | 57 +++++++------ tests/inc/IntegrationTestCase.php | 32 ++++--- tests/inc/TestPrinter.php | 4 +- tests/inc/TestSymfonyKernel.php | 14 ++-- tests/inc/TestSymfonyKernel6.php | 9 +- 51 files changed, 482 insertions(+), 596 deletions(-) diff --git a/src/Bridges/Dibi/Dibi3Adapter.php b/src/Bridges/Dibi/Dibi3Adapter.php index 684c296..05dd5c3 100644 --- a/src/Bridges/Dibi/Dibi3Adapter.php +++ b/src/Bridges/Dibi/Dibi3Adapter.php @@ -9,7 +9,7 @@ namespace Nextras\Migrations\Bridges\Dibi; -use DateTime; +use DateTimeInterface; use Dibi; use Nextras\Migrations\IDbal; @@ -26,7 +26,7 @@ public function __construct(Dibi\Connection $dibi) } - public function query($sql) + public function query(string $sql): array { $result = $this->conn->nativeQuery($sql); $result->setRowClass(null); @@ -34,37 +34,38 @@ public function query($sql) } - public function exec($sql) + public function exec(string $sql): int { - return $this->conn->nativeQuery($sql); + $this->conn->nativeQuery($sql); + return $this->conn->getAffectedRows(); } - public function escapeString($value) + public function escapeString(string $value): string { return $this->conn->getDriver()->escapeText($value); } - public function escapeInt($value) + public function escapeInt(int $value): string { - return (string) (int) $value; + return (string) $value; } - public function escapeBool($value) + public function escapeBool(bool $value): string { - return $this->conn->getDriver()->escapeBool($value); + return (string) $this->conn->getDriver()->escapeBool($value); } - public function escapeDateTime(DateTime $value) + public function escapeDateTime(DateTimeInterface $value): string { return $this->conn->getDriver()->escapeDateTime($value); } - public function escapeIdentifier($value) + public function escapeIdentifier(string $value): string { return $this->conn->getDriver()->escapeIdentifier($value); } diff --git a/src/Bridges/Dibi/DibiAdapter.php b/src/Bridges/Dibi/DibiAdapter.php index ea8f8aa..e8807e2 100644 --- a/src/Bridges/Dibi/DibiAdapter.php +++ b/src/Bridges/Dibi/DibiAdapter.php @@ -9,8 +9,9 @@ namespace Nextras\Migrations\Bridges\Dibi; -use DateTime; +use DateTimeInterface; use dibi; +use Dibi\Connection; use LogicException; use Nextras\Migrations\IDbal; @@ -21,7 +22,7 @@ class DibiAdapter implements IDbal private $innerAdapter; - public function __construct($conn) + public function __construct(Connection $conn) { if (version_compare(dibi::VERSION, '3.0.0', '>=')) { $this->innerAdapter = new Dibi3Adapter($conn); @@ -32,43 +33,43 @@ public function __construct($conn) } - public function query($sql) + public function query(string $sql): array { return $this->innerAdapter->query($sql); } - public function exec($sql) + public function exec(string $sql): int { return $this->innerAdapter->exec($sql); } - public function escapeString($value) + public function escapeString(string $value): string { return $this->innerAdapter->escapeString($value); } - public function escapeInt($value) + public function escapeInt(int $value): string { return $this->innerAdapter->escapeInt($value); } - public function escapeBool($value) + public function escapeBool(bool $value): string { return $this->innerAdapter->escapeBool($value); } - public function escapeDateTime(DateTime $value) + public function escapeDateTime(DateTimeInterface $value): string { return $this->innerAdapter->escapeDateTime($value); } - public function escapeIdentifier($value) + public function escapeIdentifier(string $value): string { return $this->innerAdapter->escapeIdentifier($value); } diff --git a/src/Bridges/DoctrineDbal/DoctrineAdapter.php b/src/Bridges/DoctrineDbal/DoctrineAdapter.php index 3896244..64d9da5 100644 --- a/src/Bridges/DoctrineDbal/DoctrineAdapter.php +++ b/src/Bridges/DoctrineDbal/DoctrineAdapter.php @@ -9,7 +9,7 @@ namespace Nextras\Migrations\Bridges\DoctrineDbal; -use DateTime; +use DateTimeInterface; use Doctrine; use Nextras\Migrations\IDbal; @@ -26,7 +26,7 @@ public function __construct(Doctrine\DBAL\Connection $conn) } - public function query($sql) + public function query(string $sql): array { return method_exists($this->conn, 'fetchAllAssociative') ? $this->conn->fetchAllAssociative($sql) @@ -34,7 +34,7 @@ public function query($sql) } - public function exec($sql) + public function exec(string $sql): int { return method_exists($this->conn, 'executeStatement') ? $this->conn->executeStatement($sql) @@ -42,31 +42,31 @@ public function exec($sql) } - public function escapeString($value) + public function escapeString(string $value): string { return $this->conn->quote($value, 'string'); } - public function escapeInt($value) + public function escapeInt(int $value): string { return $this->conn->quote($value, 'integer'); } - public function escapeBool($value) + public function escapeBool(bool $value): string { return $this->conn->quote($value, 'boolean'); } - public function escapeDateTime(DateTime $value) + public function escapeDateTime(DateTimeInterface $value): string { return $this->conn->quote($value, 'datetime'); } - public function escapeIdentifier($value) + public function escapeIdentifier(string $value): string { return $this->conn->quoteIdentifier($value); } diff --git a/src/Bridges/DoctrineOrm/StructureDiffGenerator.php b/src/Bridges/DoctrineOrm/StructureDiffGenerator.php index 80c7e5c..daf1f80 100644 --- a/src/Bridges/DoctrineOrm/StructureDiffGenerator.php +++ b/src/Bridges/DoctrineOrm/StructureDiffGenerator.php @@ -25,30 +25,20 @@ class StructureDiffGenerator implements IDiffGenerator private $ignoredQueriesFile; - /** - * @param EntityManagerInterface $entityManager - * @param string|NULL $ignoredQueriesFile - */ - public function __construct(EntityManagerInterface $entityManager, $ignoredQueriesFile = null) + public function __construct(EntityManagerInterface $entityManager, ?string $ignoredQueriesFile = null) { $this->entityManager = $entityManager; $this->ignoredQueriesFile = $ignoredQueriesFile; } - /** - * @return string - */ - public function getExtension() + public function getExtension(): string { return 'sql'; } - /** - * @return string - */ - public function generateContent() + public function generateContent(): string { $queries = array_diff($this->getUpdateQueries(), $this->getIgnoredQueries()); $content = $queries ? (implode(";\n", $queries) . ";\n") : ''; @@ -58,9 +48,9 @@ public function generateContent() /** - * @return string[] + * @return list */ - protected function getUpdateQueries() + protected function getUpdateQueries(): array { $cache = $this->entityManager->getConfiguration()->getMetadataCacheImpl(); if ($cache instanceof ClearableCache) { @@ -76,9 +66,9 @@ protected function getUpdateQueries() /** - * @return string[] + * @return list */ - protected function getIgnoredQueries() + protected function getIgnoredQueries(): array { if ($this->ignoredQueriesFile === null) { return []; diff --git a/src/Bridges/NetteDI/MigrationsExtension.php b/src/Bridges/NetteDI/MigrationsExtension.php index 931dad2..c837f07 100644 --- a/src/Bridges/NetteDI/MigrationsExtension.php +++ b/src/Bridges/NetteDI/MigrationsExtension.php @@ -13,6 +13,8 @@ use Dibi; use Nette; use Nette\DI\ContainerBuilder; +use Nette\DI\ServiceDefinition; +use Nette\DI\Statement; use Nette\Utils\Strings; use Nette\Utils\Validators; use Nextras; @@ -27,7 +29,7 @@ class MigrationsExtension extends Nette\DI\CompilerExtension /** attributes = ['for' => names of target migration extensions, 'extension' => name of handled file extension] */ const TAG_EXTENSION_HANDLER = 'nextras.migrations.extensionHandler'; - /** @var array */ + /** @var array */ public $defaults = [ 'dir' => null, 'phpParams' => [], @@ -40,7 +42,7 @@ class MigrationsExtension extends Nette\DI\CompilerExtension 'ignoredQueriesFile' => null, ]; - /** @var array */ + /** @var array */ protected $dbals = [ 'dibi' => Nextras\Migrations\Bridges\Dibi\DibiAdapter::class, 'dibi3' => Nextras\Migrations\Bridges\Dibi\Dibi3Adapter::class, @@ -50,20 +52,20 @@ class MigrationsExtension extends Nette\DI\CompilerExtension 'nextras' => Nextras\Migrations\Bridges\NextrasDbal\NextrasAdapter::class, ]; - /** @var array */ + /** @var array */ protected $drivers = [ 'mysql' => Nextras\Migrations\Drivers\MySqlDriver::class, 'pgsql' => Nextras\Migrations\Drivers\PgSqlDriver::class, ]; - /** @var array */ + /** @var array */ protected $printers = [ 'console' => Nextras\Migrations\Printers\Console::class, 'psrLog' => Nextras\Migrations\Bridges\PsrLog\PsrLogPrinter::class, ]; - public function loadConfiguration() + public function loadConfiguration(): void { $config = $this->validateConfig($this->defaults); @@ -109,7 +111,7 @@ public function loadConfiguration() } - public function beforeCompile() + public function beforeCompile(): void { $builder = $this->getContainerBuilder(); $config = $this->validateConfig($this->defaults); @@ -160,6 +162,10 @@ public function beforeCompile() } + /** + * @param null|string|Statement $dbal + * @return string|ServiceDefinition + */ private function getDbalDefinition($dbal) { $factory = $this->getDbalFactory($dbal); @@ -179,9 +185,13 @@ private function getDbalDefinition($dbal) } + /** + * @param null|string|Statement $dbal + * @return string|Statement|null + */ private function getDbalFactory($dbal) { - if ($dbal instanceof Nette\DI\Statement) { + if ($dbal instanceof Statement) { return $this->filterArguments([$dbal])[0]; } elseif (is_string($dbal) && isset($this->dbals[$dbal])) { @@ -196,6 +206,11 @@ private function getDbalFactory($dbal) } + /** + * @param null|string|Statement $driver + * @param string|ServiceDefinition $dbal + * @return string|ServiceDefinition + */ private function getDriverDefinition($driver, $dbal) { $factory = $this->getDriverFactory($driver, $dbal); @@ -215,13 +230,18 @@ private function getDriverDefinition($driver, $dbal) } + /** + * @param null|string|Statement $driver + * @param string|ServiceDefinition $dbal + * @return string|Statement|null + */ private function getDriverFactory($driver, $dbal) { - if ($driver instanceof Nette\DI\Statement) { + if ($driver instanceof Statement) { return $this->filterArguments([$driver])[0]; } elseif (is_string($driver) && isset($this->drivers[$driver])) { - return new Nette\DI\Statement($this->drivers[$driver], [$dbal]); + return new Statement($this->drivers[$driver], [$dbal]); } else { return null; @@ -229,6 +249,10 @@ private function getDriverFactory($driver, $dbal) } + /** + * @param null|string|Statement $printer + * @return string|ServiceDefinition + */ private function getPrinterDefinition($printer) { $factory = $this->getPrinterFactory($printer); @@ -248,9 +272,13 @@ private function getPrinterDefinition($printer) } + /** + * @param null|string|Statement $printer + * @return string|Statement|null + */ private function getPrinterFactory($printer) { - if ($printer instanceof Nette\DI\Statement) { + if ($printer instanceof Statement) { return $this->filterArguments([$printer])[0]; } elseif (is_string($printer) && isset($this->printers[$printer])) { @@ -265,15 +293,19 @@ private function getPrinterFactory($printer) } - private function createDefaultGroupConfiguration($dir, $withDummyData) + /** + * @param string|Nette\PhpGenerator\PhpLiteral $dir + * @return array, generator?: ServiceDefinition|null}> + */ + private function createDefaultGroupConfiguration($dir, bool $withDummyData): array { if ($dir instanceof Nette\PhpGenerator\PhpLiteral) { - $append = function ($path) use ($dir) { + $append = function (string $path) use ($dir): Nette\PhpGenerator\PhpLiteral { return ContainerBuilder::literal('? . ?', [$dir, $path]); }; } else { - $append = function ($path) use ($dir) { + $append = function (string $path) use ($dir): string { return $dir . $path; }; } @@ -305,7 +337,11 @@ private function createDefaultGroupConfiguration($dir, $withDummyData) } - private function createGroupDefinitions(array $groups) + /** + * @param array, generator?: ServiceDefinition}> $groups + * @return list + */ + private function createGroupDefinitions(array $groups): array { $builder = $this->getContainerBuilder(); $groupDefinitions = []; @@ -334,7 +370,12 @@ private function createGroupDefinitions(array $groups) } - private function createExtensionHandlerDefinitions($driver, $phpParams) + /** + * @param string|ServiceDefinition $driver + * @param array $phpParams + * @return list + */ + private function createExtensionHandlerDefinitions($driver, array $phpParams): array { $builder = $this->getContainerBuilder(); @@ -354,7 +395,7 @@ private function createExtensionHandlerDefinitions($driver, $phpParams) } - private function createConfigurationDefinition() + private function createConfigurationDefinition(): ServiceDefinition { return $this->getContainerBuilder() ->addDefinition($this->prefix('configuration')) @@ -363,7 +404,7 @@ private function createConfigurationDefinition() } - private function createDoctrineStructureDiffGeneratorDefinition($ignoredQueriesFile) + private function createDoctrineStructureDiffGeneratorDefinition(?string $ignoredQueriesFile): ServiceDefinition { $builder = $this->getContainerBuilder(); @@ -375,7 +416,12 @@ private function createDoctrineStructureDiffGeneratorDefinition($ignoredQueriesF } - private function createSymfonyCommandDefinitions($driver, $configuration, $printer) + /** + * @param string|ServiceDefinition $driver + * @param string|ServiceDefinition $configuration + * @param string|ServiceDefinition $printer + */ + private function createSymfonyCommandDefinitions($driver, $configuration, $printer): void { $builder = $this->getContainerBuilder(); $builder->addExcludedClasses([Nextras\Migrations\Bridges\SymfonyConsole\BaseCommand::class]); @@ -397,7 +443,7 @@ private function createSymfonyCommandDefinitions($driver, $configuration, $print } - private function filterArguments(array $arguments) + private function filterArguments(array $arguments): array { if (method_exists(Nette\DI\Helpers::class, 'filterArguments')) { return Nette\DI\Helpers::filterArguments($arguments); diff --git a/src/Bridges/NetteDatabase/NetteAdapter.php b/src/Bridges/NetteDatabase/NetteAdapter.php index 0d0073e..5327528 100644 --- a/src/Bridges/NetteDatabase/NetteAdapter.php +++ b/src/Bridges/NetteDatabase/NetteAdapter.php @@ -9,7 +9,7 @@ namespace Nextras\Migrations\Bridges\NetteDatabase; -use DateTime; +use DateTimeInterface; use Nette; use Nextras\Migrations\IDbal; use PDO; @@ -27,7 +27,7 @@ public function __construct(Nette\Database\Connection $ndb) } - public function query($sql) + public function query(string $sql): array { return array_map( function ($row) { return (array) $row; }, @@ -36,37 +36,37 @@ function ($row) { return (array) $row; }, } - public function exec($sql) + public function exec(string $sql): int { return $this->conn->query($sql)->getRowCount(); } - public function escapeString($value) + public function escapeString(string $value): string { return $this->conn->quote($value, PDO::PARAM_STR); } - public function escapeInt($value) + public function escapeInt(int $value): string { return $this->conn->quote((string) $value, PDO::PARAM_INT); } - public function escapeBool($value) + public function escapeBool(bool $value): string { return $this->escapeString((string) (int) $value); } - public function escapeDateTime(DateTime $value) + public function escapeDateTime(DateTimeInterface $value): string { return $this->conn->getSupplementalDriver()->formatDateTime($value); } - public function escapeIdentifier($value) + public function escapeIdentifier(string $value): string { return $this->conn->getSupplementalDriver()->delimite($value); } diff --git a/src/Bridges/NextrasDbal/NextrasAdapter.php b/src/Bridges/NextrasDbal/NextrasAdapter.php index ebb5912..1cacb0e 100644 --- a/src/Bridges/NextrasDbal/NextrasAdapter.php +++ b/src/Bridges/NextrasDbal/NextrasAdapter.php @@ -9,7 +9,7 @@ namespace Nextras\Migrations\Bridges\NextrasDbal; -use DateTime; +use DateTimeInterface; use Nextras\Dbal\Connection; use Nextras\Dbal\Drivers\IDriver; use Nextras\Dbal\Result\Row; @@ -42,7 +42,7 @@ public function __construct(Connection $connection) } - public function query($sql) + public function query(string $sql): array { return array_map( function (Row $row) { return $row->toArray(); }, @@ -51,14 +51,14 @@ function (Row $row) { return $row->toArray(); }, } - public function exec($sql) + public function exec(string $sql): int { $this->conn->query('%raw', $sql); return $this->conn->getAffectedRows(); } - public function escapeString($value) + public function escapeString(string $value): string { if ($this->version >= 2) { return $this->conn->getDriver()->convertStringToSql($value); @@ -68,13 +68,13 @@ public function escapeString($value) } - public function escapeInt($value) + public function escapeInt(int $value): string { return (string) (int) $value; } - public function escapeBool($value) + public function escapeBool(bool $value): string { if ($this->version >= 5) { return $this->conn->getPlatform()->formatBool($value); @@ -86,7 +86,7 @@ public function escapeBool($value) } - public function escapeDateTime(DateTime $value) + public function escapeDateTime(DateTimeInterface $value): string { if ($this->version >= 5) { return $this->conn->getPlatform()->formatDateTime($value); @@ -98,7 +98,7 @@ public function escapeDateTime(DateTime $value) } - public function escapeIdentifier($value) + public function escapeIdentifier(string $value): string { if ($this->version >= 5) { return $this->conn->getPlatform()->formatIdentifier($value); diff --git a/src/Bridges/PsrLog/PsrLogPrinter.php b/src/Bridges/PsrLog/PsrLogPrinter.php index f601c67..fc1539d 100644 --- a/src/Bridges/PsrLog/PsrLogPrinter.php +++ b/src/Bridges/PsrLog/PsrLogPrinter.php @@ -27,13 +27,13 @@ public function __construct(LoggerInterface $logger) } - public function printIntro($mode) + public function printIntro(string $mode): void { $this->logger->info("Nextras Migrations: started in $mode mode"); } - public function printToExecute(array $toExecute) + public function printToExecute(array $toExecute): void { $count = count($toExecute); @@ -46,7 +46,7 @@ public function printToExecute(array $toExecute) } - public function printExecute(File $file, $count, $time) + public function printExecute(File $file, int $count, float $time): void { $this->logger->info("Nextras Migrations: {$file->group->name}/{$file->name} successfully executed", [ 'queryCount' => $count, @@ -55,19 +55,19 @@ public function printExecute(File $file, $count, $time) } - public function printDone() + public function printDone(): void { $this->logger->info('Nextras Migrations: done'); } - public function printError(Exception $e) + public function printError(Exception $e): void { throw $e; } - public function printSource($code) + public function printSource(string $code): void { $this->logger->debug("Nextras Migrations: init source:\n\n$code"); } diff --git a/src/Bridges/SymfonyBundle/DependencyInjection/Configuration.php b/src/Bridges/SymfonyBundle/DependencyInjection/Configuration.php index df19575..d422257 100644 --- a/src/Bridges/SymfonyBundle/DependencyInjection/Configuration.php +++ b/src/Bridges/SymfonyBundle/DependencyInjection/Configuration.php @@ -15,7 +15,7 @@ class Configuration implements ConfigurationInterface { - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { if (!method_exists(TreeBuilder::class, '__construct')) { // Symfony < 4.2.0 $treeBuilder = new TreeBuilder(); diff --git a/src/Bridges/SymfonyBundle/DependencyInjection/NextrasMigrationsExtension.php b/src/Bridges/SymfonyBundle/DependencyInjection/NextrasMigrationsExtension.php index d8192c0..1e29673 100644 --- a/src/Bridges/SymfonyBundle/DependencyInjection/NextrasMigrationsExtension.php +++ b/src/Bridges/SymfonyBundle/DependencyInjection/NextrasMigrationsExtension.php @@ -17,7 +17,7 @@ class NextrasMigrationsExtension extends Extension { - /** @var array */ + /** @var array */ protected $dbals = [ 'dibi' => Nextras\Migrations\Bridges\Dibi\DibiAdapter::class, 'dibi3' => Nextras\Migrations\Bridges\Dibi\Dibi3Adapter::class, @@ -27,20 +27,20 @@ class NextrasMigrationsExtension extends Extension 'nextras' => Nextras\Migrations\Bridges\NextrasDbal\NextrasAdapter::class, ]; - /** @var array */ + /** @var array */ protected $drivers = [ 'mysql' => Nextras\Migrations\Drivers\MySqlDriver::class, 'pgsql' => Nextras\Migrations\Drivers\PgSqlDriver::class, ]; - /** @var array */ + /** @var array */ protected $printers = [ 'console' => Nextras\Migrations\Printers\Console::class, 'psrLog' => Nextras\Migrations\Bridges\PsrLog\PsrLogPrinter::class, ]; - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $config = $this->processConfiguration(new Configuration(), $configs); diff --git a/src/Bridges/SymfonyConsole/BaseCommand.php b/src/Bridges/SymfonyConsole/BaseCommand.php index c7a25c6..13a3f16 100644 --- a/src/Bridges/SymfonyConsole/BaseCommand.php +++ b/src/Bridges/SymfonyConsole/BaseCommand.php @@ -29,26 +29,19 @@ abstract class BaseCommand extends Command protected $printer; - /** - * @param IDriver $driver - * @param IConfiguration $config - * @param IPrinter|NULL $printer - */ - public function __construct(IDriver $driver, IConfiguration $config, IPrinter $printer = NULL) + public function __construct(IDriver $driver, IConfiguration $config, ?IPrinter $printer = null) { $this->driver = $driver; $this->config = $config; - $this->printer = $printer ?: new Console(); + $this->printer = $printer ?? new Console(); parent::__construct(); } /** - * @param string $mode Runner::MODE_* - * @param IConfiguration $config - * @return int + * @param Runner::MODE_* $mode */ - protected function runMigrations($mode, $config) + protected function runMigrations(string $mode, IConfiguration $config): int { $runner = new Runner($this->driver, $this->printer); $runner->run($mode, $config); diff --git a/src/Bridges/SymfonyConsole/ContinueCommand.php b/src/Bridges/SymfonyConsole/ContinueCommand.php index b329e5c..88821b1 100644 --- a/src/Bridges/SymfonyConsole/ContinueCommand.php +++ b/src/Bridges/SymfonyConsole/ContinueCommand.php @@ -22,7 +22,8 @@ class ContinueCommand extends BaseCommand /** @var string */ protected static $defaultDescription = 'Updates database schema by running all new migrations'; - protected function configure() + + protected function configure(): void { $this->setName(self::$defaultName); $this->setDescription(self::$defaultDescription); @@ -30,7 +31,7 @@ protected function configure() } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { return $this->runMigrations(Runner::MODE_CONTINUE, $this->config); } diff --git a/src/Bridges/SymfonyConsole/CreateCommand.php b/src/Bridges/SymfonyConsole/CreateCommand.php index de1294d..8dfe188 100644 --- a/src/Bridges/SymfonyConsole/CreateCommand.php +++ b/src/Bridges/SymfonyConsole/CreateCommand.php @@ -37,20 +37,13 @@ class CreateCommand extends BaseCommand protected $defaultContentSource = self::CONTENT_SOURCE_DIFF; - /** - * @param string $defaultContentSource - * @return void - */ - public function setDefaultContentSource($defaultContentSource) + public function setDefaultContentSource(string $defaultContentSource): void { $this->defaultContentSource = $defaultContentSource; } - /** - * @return void - */ - protected function configure() + protected function configure(): void { $this->setName(self::$defaultName); $this->setDescription(self::$defaultDescription); @@ -65,12 +58,7 @@ protected function configure() } - /** - * @param InputInterface $input - * @param OutputInterface $output - * @return int - */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $group = $this->getGroup($input->getArgument('type')); $path = $this->getPath($group, $input->getArgument('label')); @@ -83,12 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } - /** - * @param Group $group - * @param string $label - * @return string - */ - protected function getPath(Group $group, $label) + protected function getPath(Group $group, string $label): string { $dir = $group->directory; $extension = $group->generator ? $group->generator->getExtension() : 'sql'; @@ -108,11 +91,7 @@ protected function getPath(Group $group, $label) } - /** - * @param string $type - * @return Group - */ - protected function getGroup($type) + protected function getGroup(string $type): Group { $groupNamePattern = preg_quote($type, '~'); $groupNamePattern = str_replace('\\-', '\\w*+\\-', $groupNamePattern); @@ -143,12 +122,7 @@ protected function getGroup($type) } - /** - * @param string $label - * @param string $extension - * @return string - */ - protected function getFileName($label, $extension) + protected function getFileName(string $label, string $extension): string { if (preg_match('#^[a-z0-9.-]++$#i', $label)) { $slug = strtolower($label); @@ -171,12 +145,7 @@ class_exists(AsciiSlugger::class) } - /** - * @param string $dir - * @param string|NULL $found - * @return bool - */ - protected function hasNumericSubdirectory($dir, &$found) + protected function hasNumericSubdirectory(string $dir, ?string &$found): bool { $items = @scandir($dir); // directory may not exist @@ -193,10 +162,7 @@ protected function hasNumericSubdirectory($dir, &$found) } - /** - * @return string - */ - protected function getTypeArgDescription() + protected function getTypeArgDescription(): string { $options = []; $groups = $this->config->getGroups(); @@ -222,11 +188,7 @@ protected function getTypeArgDescription() } - /** - * @param InputInterface $input - * @return string - */ - protected function getFileContentSource(InputInterface $input) + protected function getFileContentSource(InputInterface $input): string { if ($input->getOption('diff')) { return self::CONTENT_SOURCE_DIFF; @@ -243,12 +205,7 @@ protected function getFileContentSource(InputInterface $input) } - /** - * @param Group $group - * @param string $source - * @return string - */ - protected function getFileContent(Group $group, $source) + protected function getFileContent(Group $group, string $source): string { if ($source === self::CONTENT_SOURCE_DIFF && $group->generator !== null) { return $group->generator->generateContent(); @@ -262,13 +219,7 @@ protected function getFileContent(Group $group, $source) } - /** - * @param string $path - * @param string $content - * @param OutputInterface $output - * @return void - */ - protected function createFile($path, $content, OutputInterface $output) + protected function createFile(string $path, string $content, OutputInterface $output): void { @mkdir(dirname($path), 0777, true); // directory may already exist diff --git a/src/Bridges/SymfonyConsole/ResetCommand.php b/src/Bridges/SymfonyConsole/ResetCommand.php index 05d9aaa..405f800 100644 --- a/src/Bridges/SymfonyConsole/ResetCommand.php +++ b/src/Bridges/SymfonyConsole/ResetCommand.php @@ -23,7 +23,7 @@ class ResetCommand extends BaseCommand protected static $defaultDescription = 'Drops current database and recreates it from scratch'; - protected function configure() + protected function configure(): void { $this->setName(self::$defaultName); $this->setDescription(self::$defaultDescription); @@ -31,7 +31,7 @@ protected function configure() } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { return $this->runMigrations(Runner::MODE_RESET, $this->config); } diff --git a/src/Configurations/Configuration.php b/src/Configurations/Configuration.php index 217ac42..567d2f7 100644 --- a/src/Configurations/Configuration.php +++ b/src/Configurations/Configuration.php @@ -19,16 +19,16 @@ */ class Configuration implements IConfiguration { - /** @var Group[] */ + /** @var list */ private $groups; - /** @var IExtensionHandler[] (extension => IExtensionHandler) */ + /** @var array (extension => IExtensionHandler) */ private $extensionHandlers; /** - * @param Group[] $groups - * @param IExtensionHandler[] $extensionHandlers (extension => IExtensionHandler) + * @param list $groups + * @param array $extensionHandlers (extension => IExtensionHandler) */ public function __construct(array $groups, array $extensionHandlers) { @@ -37,19 +37,13 @@ public function __construct(array $groups, array $extensionHandlers) } - /** - * @return Group[] - */ - public function getGroups() + public function getGroups(): array { return $this->groups; } - /** - * @return IExtensionHandler[] (extension => IExtensionHandler) - */ - public function getExtensionHandlers() + public function getExtensionHandlers(): array { return $this->extensionHandlers; } diff --git a/src/Configurations/DefaultConfiguration.php b/src/Configurations/DefaultConfiguration.php index 12fbacd..fc71bbb 100644 --- a/src/Configurations/DefaultConfiguration.php +++ b/src/Configurations/DefaultConfiguration.php @@ -33,29 +33,26 @@ class DefaultConfiguration implements IConfiguration /** @var bool */ protected $withDummyData; - /** @var array */ + /** @var array */ protected $phpParams; - /** @var Group[] */ + /** @var list */ protected $groups; - /** @var IExtensionHandler[] */ + /** @var array */ protected $handlers; - /** @var IDiffGenerator|NULL */ + /** @var ?IDiffGenerator */ protected $structureDiffGenerator; - /** @var IDiffGenerator|NULL */ + /** @var ?IDiffGenerator */ protected $dummyDataDiffGenerator; /** - * @param string $dir - * @param IDriver $driver - * @param bool $withDummyData - * @param array $phpParams + * @param array $phpParams */ - public function __construct($dir, IDriver $driver, $withDummyData = true, array $phpParams = []) + public function __construct(string $dir, IDriver $driver, bool $withDummyData = true, array $phpParams = []) { $this->dir = $dir; $this->driver = $driver; @@ -64,10 +61,7 @@ public function __construct($dir, IDriver $driver, $withDummyData = true, array } - /** - * @return Group[] - */ - public function getGroups() + public function getGroups(): array { if ($this->groups === null) { $structures = new Group(); @@ -97,10 +91,7 @@ public function getGroups() } - /** - * @return array|IExtensionHandler[] (extension => IExtensionHandler) - */ - public function getExtensionHandlers() + public function getExtensionHandlers(): array { if ($this->handlers === null) { $this->handlers = [ @@ -113,21 +104,13 @@ public function getExtensionHandlers() } - /** - * @param IDiffGenerator|NULL $generator - * @return void - */ - public function setStructureDiffGenerator(IDiffGenerator $generator = null) + public function setStructureDiffGenerator(?IDiffGenerator $generator = null): void { $this->structureDiffGenerator = $generator; } - /** - * @param IDiffGenerator|NULL $generator - * @return void - */ - public function setDummyDataDiffGenerator(IDiffGenerator $generator = null) + public function setDummyDataDiffGenerator(?IDiffGenerator $generator = null): void { $this->dummyDataDiffGenerator = $generator; } diff --git a/src/Controllers/BaseController.php b/src/Controllers/BaseController.php index 9fc20bf..2295c10 100644 --- a/src/Controllers/BaseController.php +++ b/src/Controllers/BaseController.php @@ -13,6 +13,7 @@ use Nextras\Migrations\Entities\Group; use Nextras\Migrations\IDriver; use Nextras\Migrations\IExtensionHandler; +use Nextras\Migrations\IPrinter; abstract class BaseController @@ -23,7 +24,7 @@ abstract class BaseController /** @var string */ protected $mode; - /** @var array (name => Group) */ + /** @var array (name => Group) */ protected $groups; @@ -36,10 +37,13 @@ public function __construct(IDriver $driver) } - abstract public function run(); + abstract public function run(): void; - public function addGroup($name, $dir, array $dependencies = []) + /** + * @param list $dependencies + */ + public function addGroup(string $name, string $dir, array $dependencies = []): self { $group = new Group; $group->name = $name; @@ -52,32 +56,38 @@ public function addGroup($name, $dir, array $dependencies = []) } - public function addExtension($extension, IExtensionHandler $handler) + public function addExtension(string $extension, IExtensionHandler $handler): self { $this->runner->addExtensionHandler($extension, $handler); return $this; } - protected function registerGroups() + /** + * @return list + */ + protected function registerGroups(): array { $enabled = []; + foreach ($this->groups as $group) { $this->runner->addGroup($group); + if ($group->enabled) { $enabled[] = $group->name; } } + return $enabled; } - protected function setupPhp() + protected function setupPhp(): void { @set_time_limit(0); @ini_set('memory_limit', '1G'); } - abstract protected function createPrinter(); + abstract protected function createPrinter(): IPrinter; } diff --git a/src/Controllers/ConsoleController.php b/src/Controllers/ConsoleController.php index 3f4dde7..08a8caf 100644 --- a/src/Controllers/ConsoleController.php +++ b/src/Controllers/ConsoleController.php @@ -10,12 +10,13 @@ namespace Nextras\Migrations\Controllers; use Nextras\Migrations\Engine; +use Nextras\Migrations\IPrinter; use Nextras\Migrations\Printers; class ConsoleController extends BaseController { - public function run() + public function run(): void { $this->processArguments(); $this->printHeader(); @@ -24,7 +25,7 @@ public function run() } - private function printHeader() + private function printHeader(): void { if ($this->mode === Engine\Runner::MODE_INIT) { printf("-- Migrations init\n"); @@ -35,7 +36,7 @@ private function printHeader() } - private function processArguments() + private function processArguments(): void { $arguments = array_slice($_SERVER['argv'], 1); $help = count($arguments) === 0; @@ -88,7 +89,7 @@ private function processArguments() } - protected function createPrinter() + protected function createPrinter(): IPrinter { return new Printers\Console(); } diff --git a/src/Controllers/HttpController.php b/src/Controllers/HttpController.php index 8176a55..8857f1e 100644 --- a/src/Controllers/HttpController.php +++ b/src/Controllers/HttpController.php @@ -10,6 +10,7 @@ namespace Nextras\Migrations\Controllers; use Nextras\Migrations\Engine; +use Nextras\Migrations\IPrinter; use Nextras\Migrations\Printers; @@ -22,14 +23,14 @@ class HttpController extends BaseController private $error; - public function run() + public function run(): void { $this->processArguments(); $this->executeAction(); } - private function processArguments() + private function processArguments(): void { if (isset($_GET['action'])) { if ($_GET['action'] === 'run' || $_GET['action'] === 'css') { @@ -87,14 +88,14 @@ private function processArguments() } - private function executeAction() + private function executeAction(): void { $method = 'action' . ucfirst($this->action); $this->$method(); } - private function actionIndex() + private function actionIndex(): void { $combinations = $this->getGroupsCombinations(); $this->printHeader(); @@ -122,7 +123,7 @@ private function actionIndex() } - private function actionRun() + private function actionRun(): void { $groups = $this->registerGroups(); $groups = implode(' + ', $groups); @@ -135,14 +136,14 @@ private function actionRun() } - private function actionCss() + private function actionCss(): void { header('Content-Type: text/css', true); readfile(__DIR__ . '/templates/main.css'); } - private function actionError() + private function actionError(): void { $this->printHeader(); echo "

    Migrations – error

    \n"; @@ -150,7 +151,10 @@ private function actionError() } - private function getGroupsCombinations() + /** + * @return list> + */ + private function getGroupsCombinations(): array { $groups = []; $index = 1; @@ -183,13 +187,13 @@ private function getGroupsCombinations() } - private function printHeader() + private function printHeader(): void { readfile(__DIR__ . '/templates/header.phtml'); } - protected function createPrinter() + protected function createPrinter(): IPrinter { return new Printers\HtmlDump(); } diff --git a/src/Drivers/BaseDriver.php b/src/Drivers/BaseDriver.php index 508edbe..6c942d7 100644 --- a/src/Drivers/BaseDriver.php +++ b/src/Drivers/BaseDriver.php @@ -31,18 +31,14 @@ abstract class BaseDriver implements IDriver protected $tableNameQuoted; - /** - * @param IDbal $dbal - * @param string $tableName - */ - public function __construct(IDbal $dbal, $tableName = 'migrations') + public function __construct(IDbal $dbal, string $tableName = 'migrations') { $this->dbal = $dbal; $this->tableName = $tableName; } - public function setupConnection() + public function setupConnection(): void { $this->tableNameQuoted = $this->dbal->escapeIdentifier($this->tableName); } @@ -56,11 +52,8 @@ public function setupConnection() * @author Michael Moravec * @author Jan Skrasek * @license Apache License - * - * @param string $path - * @return int number of executed queries */ - public function loadFile($path) + public function loadFile(string $path): int { $content = @file_get_contents($path); if ($content === false) { @@ -103,7 +96,7 @@ public function loadFile($path) break; } elseif ($found) { // find matching quote or comment end - $endRe = isset($endReTable[$found]) ? $endReTable[$found] : '(' . (preg_match('~^-- |^#~', $found) ? "\n" : preg_quote($found) . "|\\\\.") . '|\z)s'; + $endRe = $endReTable[$found] ?? '(' . (preg_match('~^-- |^#~', $found) ? "\n" : preg_quote($found) . "|\\\\.") . '|\z)s'; while (preg_match($endRe, $content, $match, PREG_OFFSET_CAPTURE, $parseOffset)) { //! respect sql_mode NO_BACKSLASH_ESCAPES $s = $match[0][0]; if (strlen($s) === 0) { diff --git a/src/Drivers/MySqlDriver.php b/src/Drivers/MySqlDriver.php index 8130539..0534380 100644 --- a/src/Drivers/MySqlDriver.php +++ b/src/Drivers/MySqlDriver.php @@ -22,7 +22,10 @@ */ class MySqlDriver extends BaseDriver implements IDriver { - public function setupConnection() + private const LOCK_NAME = 'Nextras.Migrations'; + + + public function setupConnection(): void { parent::setupConnection(); $this->dbal->exec('SET NAMES "utf8mb4"'); @@ -32,7 +35,7 @@ public function setupConnection() } - public function emptyDatabase() + public function emptyDatabase(): void { $rows = $this->dbal->query('SELECT DATABASE() AS `name`'); $dbName = $this->dbal->escapeIdentifier($rows[0]['name']); @@ -46,25 +49,25 @@ public function emptyDatabase() } - public function beginTransaction() + public function beginTransaction(): void { $this->dbal->exec('START TRANSACTION'); } - public function commitTransaction() + public function commitTransaction(): void { $this->dbal->exec('COMMIT'); } - public function rollbackTransaction() + public function rollbackTransaction(): void { $this->dbal->exec('ROLLBACK'); } - public function lock() + public function lock(): void { $lock = $this->dbal->escapeString(self::LOCK_NAME); $result = (int) $this->dbal->query("SELECT GET_LOCK(SHA1(CONCAT($lock, '-', DATABASE())), 3) AS `result`")[0]['result']; @@ -74,7 +77,7 @@ public function lock() } - public function unlock() + public function unlock(): void { $lock = $this->dbal->escapeString(self::LOCK_NAME); $result = (int) $this->dbal->query("SELECT RELEASE_LOCK(SHA1(CONCAT($lock, '-', DATABASE()))) AS `result`")[0]['result']; @@ -84,19 +87,19 @@ public function unlock() } - public function createTable() + public function createTable(): void { $this->dbal->exec($this->getInitTableSource()); } - public function dropTable() + public function dropTable(): void { $this->dbal->exec("DROP TABLE {$this->tableNameQuoted}"); } - public function insertMigration(Migration $migration) + public function insertMigration(Migration $migration): void { $this->dbal->exec(" INSERT INTO {$this->tableNameQuoted} @@ -113,7 +116,7 @@ public function insertMigration(Migration $migration) } - public function markMigrationAsReady(Migration $migration) + public function markMigrationAsReady(Migration $migration): void { $this->dbal->exec(" UPDATE {$this->tableNameQuoted} @@ -123,7 +126,7 @@ public function markMigrationAsReady(Migration $migration) } - public function getAllMigrations() + public function getAllMigrations(): array { $migrations = []; $result = $this->dbal->query("SELECT * FROM {$this->tableNameQuoted} ORDER BY `executed`"); @@ -153,7 +156,7 @@ public function getAllMigrations() } - public function getInitTableSource() + public function getInitTableSource(): string { return preg_replace('#^\t{3}#m', '', trim(" CREATE TABLE IF NOT EXISTS {$this->tableNameQuoted} ( @@ -170,7 +173,7 @@ public function getInitTableSource() } - public function getInitMigrationsSource(array $files) + public function getInitMigrationsSource(array $files): string { $out = ''; foreach ($files as $file) { diff --git a/src/Drivers/PgSqlDriver.php b/src/Drivers/PgSqlDriver.php index 398ba79..acb4905 100644 --- a/src/Drivers/PgSqlDriver.php +++ b/src/Drivers/PgSqlDriver.php @@ -30,51 +30,46 @@ class PgSqlDriver extends BaseDriver implements IDriver protected $schemaQuoted; - /** - * @param IDbal $dbal - * @param string $tableName - * @param string $schema - */ - public function __construct(IDbal $dbal, $tableName = 'migrations', $schema = 'public') + public function __construct(IDbal $dbal, string $tableName = 'migrations', string $schema = 'public') { parent::__construct($dbal, $tableName); $this->schema = $schema; } - public function setupConnection() + public function setupConnection(): void { parent::setupConnection(); $this->schemaQuoted = $this->dbal->escapeIdentifier($this->schema); } - public function emptyDatabase() + public function emptyDatabase(): void { $this->dbal->exec("DROP SCHEMA IF EXISTS {$this->schemaQuoted} CASCADE"); $this->dbal->exec("CREATE SCHEMA {$this->schemaQuoted}"); } - public function beginTransaction() + public function beginTransaction(): void { $this->dbal->exec('START TRANSACTION'); } - public function commitTransaction() + public function commitTransaction(): void { $this->dbal->exec('COMMIT'); } - public function rollbackTransaction() + public function rollbackTransaction(): void { $this->dbal->exec('ROLLBACK'); } - public function lock() + public function lock(): void { try { $this->dbal->exec('SELECT pg_advisory_lock(-2099128779216184107)'); @@ -85,7 +80,7 @@ public function lock() } - public function unlock() + public function unlock(): void { try { $this->dbal->exec('SELECT pg_advisory_unlock(-2099128779216184107)'); @@ -96,19 +91,19 @@ public function unlock() } - public function createTable() + public function createTable(): void { $this->dbal->exec($this->getInitTableSource()); } - public function dropTable() + public function dropTable(): void { $this->dbal->exec("DROP TABLE {$this->schemaQuoted}.{$this->tableNameQuoted}"); } - public function insertMigration(Migration $migration) + public function insertMigration(Migration $migration): void { $rows = $this->dbal->query(" INSERT INTO {$this->schemaQuoted}.{$this->tableNameQuoted}" . ' @@ -126,7 +121,7 @@ public function insertMigration(Migration $migration) } - public function markMigrationAsReady(Migration $migration) + public function markMigrationAsReady(Migration $migration): void { $this->dbal->exec(" UPDATE {$this->schemaQuoted}.{$this->tableNameQuoted}" . ' @@ -136,7 +131,7 @@ public function markMigrationAsReady(Migration $migration) } - public function getAllMigrations() + public function getAllMigrations(): array { $migrations = []; $result = $this->dbal->query("SELECT * FROM {$this->schemaQuoted}.{$this->tableNameQuoted} ORDER BY \"executed\""); @@ -166,7 +161,7 @@ public function getAllMigrations() } - public function getInitTableSource() + public function getInitTableSource(): string { return preg_replace('#^\t{3}#m', '', trim(" CREATE TABLE IF NOT EXISTS {$this->schemaQuoted}.{$this->tableNameQuoted} (" . ' @@ -183,7 +178,7 @@ public function getInitTableSource() } - public function getInitMigrationsSource(array $files) + public function getInitMigrationsSource(array $files): string { $out = ''; foreach ($files as $file) { diff --git a/src/Engine/Finder.php b/src/Engine/Finder.php index 9a1b552..0687864 100644 --- a/src/Engine/Finder.php +++ b/src/Engine/Finder.php @@ -21,12 +21,12 @@ class Finder /** * Finds files. * - * @param Group[] $groups - * @param string[] $extensions - * @return File[] + * @param list $groups + * @param list $extensions + * @return list * @throws Exception */ - public function find(array $groups, array $extensions) + public function find(array $groups, array $extensions): array { $files = []; foreach ($groups as $group) { @@ -53,9 +53,8 @@ public function find(array $groups, array $extensions) * Returns logical name of migration file. * * @param string $path relative path to group directory - * @return string */ - protected function getName($path) + protected function getName(string $path): string { $parts = explode('/', $path); $dirName = implode('-', array_slice($parts, 0, -1)); @@ -68,12 +67,10 @@ protected function getName($path) /** * Returns file extension. * - * @param File $file - * @param string[] $extensions - * @return string + * @param list $extensions * @throws Exception */ - protected function getExtension(File $file, array $extensions) + protected function getExtension(File $file, array $extensions): string { $fileExt = null; @@ -102,11 +99,7 @@ protected function getExtension(File $file, array $extensions) } - /** - * @param File $file - * @return string - */ - protected function getChecksum(File $file) + protected function getChecksum(File $file): string { $content = @file_get_contents($file->path); if ($content === false) { @@ -118,11 +111,10 @@ protected function getChecksum(File $file) /** - * @param string $dir - * @return string[] + * @return list * @throws IOException */ - protected function getFilesRecursive($dir) + protected function getFilesRecursive(string $dir): array { $items = $this->getItems($dir); foreach ($items as $i => $item) { @@ -144,10 +136,9 @@ protected function getFilesRecursive($dir) /** - * @param string $dir - * @return array + * @return list */ - protected function getItems($dir) + protected function getItems(string $dir): array { return @scandir($dir) ?: []; // directory may not exist } diff --git a/src/Engine/OrderResolver.php b/src/Engine/OrderResolver.php index 1a13768..0f77c18 100644 --- a/src/Engine/OrderResolver.php +++ b/src/Engine/OrderResolver.php @@ -18,14 +18,13 @@ class OrderResolver { /** - * @param Migration[] $migrations - * @param Group[] $groups - * @param File[] $files - * @param string $mode - * @return File[] + * @param list $migrations + * @param list $groups + * @param list $files + * @return list * @throws LogicException */ - public function resolve(array $migrations, array $groups, array $files, $mode) + public function resolve(array $migrations, array $groups, array $files, string $mode): array { $groups = $this->getAssocGroups($groups); $this->validateGroups($groups); @@ -107,13 +106,13 @@ public function resolve(array $migrations, array $groups, array $files, $mode) /** - * @param File[] $files - * @param array $groups (name => Group) - * @return File[] sorted + * @param list $files + * @param array $groups (name => Group) + * @return list sorted */ - protected function sortFiles(array $files, array $groups) + protected function sortFiles(array $files, array $groups): array { - usort($files, function (File $a, File $b) use ($groups) { + usort($files, function (File $a, File $b) use ($groups): int { $cmp = strcmp($a->name, $b->name); if ($cmp === 0 && $a !== $b) { $cmpA = $this->isGroupDependentOn($groups, $a->group, $b->group); @@ -144,16 +143,14 @@ protected function sortFiles(array $files, array $groups) /** * Returns true if groupA depends on groupB. * - * @param array $groups (name => Group) - * @param Group $groupA - * @param Group $groupB - * @return bool + * @param array $groups (name => Group) */ - protected function isGroupDependentOn(array $groups, Group $groupA, Group $groupB) + protected function isGroupDependentOn(array $groups, Group $groupA, Group $groupB): bool { $visited = []; $queue = $groupB->dependencies; $queue[] = $groupB->name; + while ($node = array_shift($queue)) { if (isset($visited[$node])) { continue; @@ -168,74 +165,100 @@ protected function isGroupDependentOn(array $groups, Group $groupA, Group $group $queue[] = $dep; } } + return false; } - protected function getAssocMigrations(array $migrations) + /** + * @param list $migrations + * @return array> (group => (filename => Migration)) + */ + protected function getAssocMigrations(array $migrations): array { $assoc = []; + foreach ($migrations as $migration) { $assoc[$migration->group][$migration->filename] = $migration; } + return $assoc; } - protected function getAssocGroups(array $groups) + /** + * @param list $groups + * @return array (name => Group) + */ + protected function getAssocGroups(array $groups): array { $assoc = []; + foreach ($groups as $group) { $assoc[$group->name] = $group; } + return $assoc; } - protected function getAssocFiles(array $files) + /** + * @param list $files + * @return array> (group => (filename => File)) + */ + protected function getAssocFiles(array $files): array { $assoc = []; + foreach ($files as $file) { $assoc[$file->group->name][$file->name] = $file; } + return $assoc; } - protected function getFlatFiles(array $files) + /** + * @param array> $files + * @return list + */ + protected function getFlatFiles(array $files): array { $flat = []; + foreach ($files as $tmp) { foreach ($tmp as $file) { $flat[] = $file; } } + return $flat; } /** - * @param File[] $files - * @return File[] first file for each group + * @param list $files + * @return array (group => File) */ - protected function getFirstFiles(array $files) + protected function getFirstFiles(array $files): array { $firstFiles = []; + foreach ($files as $file) { if (!isset($firstFiles[$file->group->name])) { $firstFiles[$file->group->name] = $file; } } + return $firstFiles; } /** - * @param Group[] $groups - * @return void + * @param array $groups * @throws LogicException */ - private function validateGroups(array $groups) + private function validateGroups(array $groups): void { foreach ($groups as $group) { foreach ($group->dependencies as $dependency) { diff --git a/src/Engine/Runner.php b/src/Engine/Runner.php index 1101870..5e49e31 100644 --- a/src/Engine/Runner.php +++ b/src/Engine/Runner.php @@ -33,10 +33,10 @@ class Runner /** @var IPrinter */ private $printer; - /** @var array (extension => IExtensionHandler) */ + /** @var array (extension => IExtensionHandler) */ private $extensionsHandlers = []; - /** @var Group[] */ + /** @var list */ private $groups = []; /** @var IDriver */ @@ -58,19 +58,14 @@ public function __construct(IDriver $driver, IPrinter $printer) } - public function addGroup(Group $group) + public function addGroup(Group $group): self { $this->groups[] = $group; return $this; } - /** - * @param string $extension - * @param IExtensionHandler $handler - * @return self - */ - public function addExtensionHandler($extension, IExtensionHandler $handler) + public function addExtensionHandler(string $extension, IExtensionHandler $handler): self { if (isset($this->extensionsHandlers[$extension])) { throw new LogicException("Extension '$extension' has already been defined."); @@ -82,11 +77,9 @@ public function addExtensionHandler($extension, IExtensionHandler $handler) /** - * @param string $mode self::MODE_CONTINUE|self::MODE_RESET|self::MODE_INIT - * @param IConfiguration $config - * @return void + * @param self::MODE_* $mode */ - public function run($mode = self::MODE_CONTINUE, IConfiguration $config = null) + public function run(string $mode = self::MODE_CONTINUE, ?IConfiguration $config = null): void { if ($config) { foreach ($config->getGroups() as $group) { @@ -142,24 +135,20 @@ public function run($mode = self::MODE_CONTINUE, IConfiguration $config = null) } - /** - * @param string $name - * @return IExtensionHandler - */ - public function getExtension($name) + public function getExtension(string $name): IExtensionHandler { if (!isset($this->extensionsHandlers[$name])) { throw new LogicException("Extension '$name' not found."); } + return $this->extensionsHandlers[$name]; } /** - * @param File $file * @return int number of executed queries */ - protected function execute(File $file) + protected function execute(File $file): int { $this->driver->beginTransaction(); @@ -173,6 +162,7 @@ protected function execute(File $file) try { $queriesCount = $this->getExtension($file->extension)->execute($file); + } catch (\Exception $e) { $this->driver->rollbackTransaction(); throw new ExecutionException(sprintf('Executing migration "%s" has failed.', $file->path), 0, $e); diff --git a/src/Entities/Group.php b/src/Entities/Group.php index 00fc2e4..146db30 100644 --- a/src/Entities/Group.php +++ b/src/Entities/Group.php @@ -26,7 +26,7 @@ class Group /** @var string absolute path do directory */ public $directory; - /** @var string[] */ + /** @var list */ public $dependencies; /** @var IDiffGenerator|null */ diff --git a/src/Extensions/PhpHandler.php b/src/Extensions/PhpHandler.php index 2f77a6c..08ab3a7 100644 --- a/src/Extensions/PhpHandler.php +++ b/src/Extensions/PhpHandler.php @@ -20,12 +20,12 @@ */ class PhpHandler implements IExtensionHandler { - /** @var array name => value */ + /** @var array name => value */ private $params; /** - * @param array $params name => value + * @param array $params (name => value) */ public function __construct(array $params = []) { @@ -34,11 +34,9 @@ public function __construct(array $params = []) /** - * @param string $name * @param mixed $value - * @return self */ - public function addParameter($name, $value) + public function addParameter(string $name, $value): self { $this->params[$name] = $value; return $this; @@ -46,25 +44,23 @@ public function addParameter($name, $value) /** - * @return array (name => value) + * @return array (name => value) */ - public function getParameters() + public function getParameters(): array { return $this->params; } - /** - * @param File $file - * @return int number of queries - */ - public function execute(File $file) + public function execute(File $file): int { extract($this->params, EXTR_SKIP); $count = @include $file->path; + if ($count === false) { throw new IOException("Cannot include file '{$file->path}'."); } + return $count; } } diff --git a/src/Extensions/SqlHandler.php b/src/Extensions/SqlHandler.php index 6996ea2..7eb61ab 100644 --- a/src/Extensions/SqlHandler.php +++ b/src/Extensions/SqlHandler.php @@ -24,25 +24,20 @@ class SqlHandler implements IExtensionHandler private $driver; - /** - * @param IDriver $driver - */ public function __construct(IDriver $driver) { $this->driver = $driver; } - /** - * @param File $file - * @return int number of queries - */ - public function execute(File $file) + public function execute(File $file): int { $count = $this->driver->loadFile($file->path); + if ($count === 0) { throw new LogicException("{$file->path} is empty"); } + return $count; } } diff --git a/src/IConfiguration.php b/src/IConfiguration.php index c354ea4..436367d 100644 --- a/src/IConfiguration.php +++ b/src/IConfiguration.php @@ -18,13 +18,13 @@ interface IConfiguration { /** - * @return Group[] + * @return list */ - public function getGroups(); + public function getGroups(): array; /** - * @return array (extension => IExtensionHandler) + * @return array (extension => IExtensionHandler) */ - public function getExtensionHandlers(); + public function getExtensionHandlers(): array; } diff --git a/src/IDbal.php b/src/IDbal.php index b020e53..2c5a4e4 100644 --- a/src/IDbal.php +++ b/src/IDbal.php @@ -9,7 +9,7 @@ namespace Nextras\Migrations; -use DateTime; +use DateTimeInterface; /** @@ -18,51 +18,28 @@ interface IDbal { /** - * @param string $sql - * @return array list of rows represented by assoc. arrays + * @return array> list of rows represented by assoc. arrays */ - function query($sql); + public function query(string $sql): array; /** - * @param string $sql * @return int number of affected rows */ - function exec($sql); + public function exec(string $sql): int; - /** - * @param string $value - * @return string escaped string wrapped in quotes - */ - function escapeString($value); + public function escapeString(string $value): string; - /** - * @param int $value - * @return string - */ - function escapeInt($value); + public function escapeInt(int $value): string; - /** - * @param bool $value - * @return string - */ - function escapeBool($value); + public function escapeBool(bool $value): string; - /** - * @param DateTime $value - * @return string - */ - function escapeDateTime(DateTime $value); - + public function escapeDateTime(DateTimeInterface $value): string; - /** - * @param string $value - * @return string - */ - function escapeIdentifier($value); + public function escapeIdentifier(string $value): string; } diff --git a/src/IDiffGenerator.php b/src/IDiffGenerator.php index 605a1d6..2ecb2f4 100644 --- a/src/IDiffGenerator.php +++ b/src/IDiffGenerator.php @@ -12,15 +12,14 @@ interface IDiffGenerator { - /** - * @return string + * @return string file extension */ - function getExtension(); + public function getExtension(): string; /** * @return string SQL (semicolon-separated queries) */ - function generateContent(); + public function generateContent(): string; } diff --git a/src/IDriver.php b/src/IDriver.php index 0c96b81..67740e0 100644 --- a/src/IDriver.php +++ b/src/IDriver.php @@ -18,112 +18,98 @@ */ interface IDriver { - /** @const shared lock identifier */ - const LOCK_NAME = 'Nextras.Migrations'; - - /** * Setups the connection, such as encoding, default schema, etc. */ - function setupConnection(); + public function setupConnection(): void; /** - * Drops the database / schema. Should removes all db objects (tables, views, procedures, sequences, ...) - * - * @return mixed + * Drops the database / schema. Should remove all db objects (tables, views, procedures, sequences, ...) */ - function emptyDatabase(); + public function emptyDatabase(): void; /** * Loads and executes SQL queries from given file. * - * @param string $path * @return int number of executed queries */ - function loadFile($path); + public function loadFile(string $path): int; /** * Starts transaction. */ - function beginTransaction(); + public function beginTransaction(): void; /** * Commit transaction. */ - function commitTransaction(); + public function commitTransaction(): void; /** * Rollback transaction. */ - function rollbackTransaction(); + public function rollbackTransaction(): void; /** * Locks database for running migrations. */ - function lock(); + public function lock(): void; /** * Unlocks database. */ - function unlock(); + public function unlock(): void; /** * Creates migration table. */ - function createTable(); + public function createTable(): void; /** * Drop migration table. */ - function dropTable(); + public function dropTable(): void; /** * Inserts migration info into migration table. - * - * @param Migration $migration */ - function insertMigration(Migration $migration); + public function insertMigration(Migration $migration): void; /** * Updated migration as executed. - * - * @param Migration $migration */ - function markMigrationAsReady(Migration $migration); + public function markMigrationAsReady(Migration $migration): void; /** * Returns all migrations stored in migration table sorted by time. * - * @return Migration[] + * @return list */ - function getAllMigrations(); + public function getAllMigrations(): array; /** * Returns source code for migration table initialization. - * - * @return string */ - function getInitTableSource(); + public function getInitTableSource(): string; /** * Returns source code for migration table data initialization. * - * @param File[] $files - * @return string + * @param list $files */ - function getInitMigrationsSource(array $files); + public function getInitMigrationsSource(array $files): string; } diff --git a/src/IExtensionHandler.php b/src/IExtensionHandler.php index ea631af..12c5551 100644 --- a/src/IExtensionHandler.php +++ b/src/IExtensionHandler.php @@ -19,8 +19,7 @@ interface IExtensionHandler { /** - * @param File $file * @return int number of queries */ - function execute(File $file); + public function execute(File $file): int; } diff --git a/src/IPrinter.php b/src/IPrinter.php index 1a83aae..71a11fe 100644 --- a/src/IPrinter.php +++ b/src/IPrinter.php @@ -18,51 +18,42 @@ interface IPrinter { /** - * Print general info about mode. - * - reset = Database has been wiped. - * - continue = Running new migrations. - * - * @param string $mode + * Prints general info about mode. */ - function printIntro($mode); + public function printIntro(string $mode): void; /** * List of migrations which should be executed has been completed. * - * @param File[] $toExecute + * @param list $toExecute */ - function printToExecute(array $toExecute); + public function printToExecute(array $toExecute): void; /** * A migration has been successfully executed. * - * @param File $file * @param int $count number of executed queries - * @param float $time elapsed time in milliseconds + * @param float $time elapsed time in seconds */ - function printExecute(File $file, $count, $time); + public function printExecute(File $file, int $count, float $time): void; /** * All migrations have been successfully executed. */ - function printDone(); + public function printDone(): void; /** * An error has occurred during execution of a migration. - * - * @param Exception $e */ - function printError(Exception $e); + public function printError(Exception $e): void; /** * Prints init source code. - * - * @param string $code */ - function printSource($code); + public function printSource(string $code): void; } diff --git a/src/Printers/Console.php b/src/Printers/Console.php index 4d42c72..6b52c3b 100644 --- a/src/Printers/Console.php +++ b/src/Printers/Console.php @@ -36,14 +36,14 @@ public function __construct() } - public function printIntro($mode) + public function printIntro(string $mode): void { $this->output('Nextras Migrations'); $this->output(strtoupper($mode), self::COLOR_INTRO); } - public function printToExecute(array $toExecute) + public function printToExecute(array $toExecute): void { if ($toExecute) { $count = count($toExecute); @@ -54,30 +54,30 @@ public function printToExecute(array $toExecute) } - public function printExecute(File $file, $count, $time) + public function printExecute(File $file, int $count, float $time): void { $this->output( '- ' . $file->group->name . '/' . $file->name . '; ' - . $this->color($count, self::COLOR_INFO) . ' queries; ' - . $this->color(sprintf('%0.3f', $time), self::COLOR_INFO) . ' s' + . $this->colorize((string) $count, self::COLOR_INFO) . ' queries; ' + . $this->colorize(sprintf('%0.3f', $time), self::COLOR_INFO) . ' s' ); } - public function printDone() + public function printDone(): void { $this->output('OK', self::COLOR_SUCCESS); } - public function printError(Exception $e) + public function printError(Exception $e): void { $this->output('ERROR: ' . $e->getMessage(), self::COLOR_ERROR); throw $e; } - public function printSource($code) + public function printSource(string $code): void { $this->output($code); } @@ -86,41 +86,27 @@ public function printSource($code) /** * Prints text to a console, optionally in a specific color. * - * @param string $s - * @param string|NULL $color self::COLOR_* + * @param string|null $color self::COLOR_* */ - protected function output($s, $color = null) + protected function output(string $s, ?string $color = null): void { - if ($color === null || !$this->useColors) { - echo "$s\n"; - } else { - echo $this->color($s, $color) . "\n"; - } + echo $this->colorize($s, $color) . "\n"; } - /** - * @param string $s - * @param string $color - * @return string - */ - protected function color($s, $color) + protected function colorize(string $s, ?string $color): string { - if (!$this->useColors) { - return $s; - } - return "\033[{$color}m$s\033[22;39m"; + return $this->useColors && $color !== null ? "\033[{$color}m$s\033[22;39m" : $s; } /** - * @return bool TRUE if terminal support colors, FALSE otherwise - * @license New BSD License - * @author David Grudl + * @return bool true if terminal support colors, false otherwise */ - protected function detectColorSupport() + protected function detectColorSupport(): bool { - return (getenv('ConEmuANSI') === 'ON' || getenv('ANSICON') !== false - || (defined('STDOUT') && function_exists('posix_isatty') && posix_isatty(STDOUT))); + return (function_exists('posix_isatty') && posix_isatty(STDOUT)) + || (function_exists('stream_isatty') && stream_isatty(STDOUT)) + || (function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(STDOUT)); } } diff --git a/src/Printers/DevNull.php b/src/Printers/DevNull.php index 36a88c6..7479e97 100644 --- a/src/Printers/DevNull.php +++ b/src/Printers/DevNull.php @@ -21,32 +21,32 @@ */ class DevNull implements IPrinter { - public function printIntro($mode) + public function printIntro(string $mode): void { } - public function printToExecute(array $toExecute) + public function printToExecute(array $toExecute): void { } - public function printExecute(File $file, $count, $time) + public function printExecute(File $file, int $count, float $time): void { } - public function printDone() + public function printDone(): void { } - public function printError(Exception $e) + public function printError(Exception $e): void { } - public function printSource($code) + public function printSource(string $code): void { } } diff --git a/src/Printers/HtmlDump.php b/src/Printers/HtmlDump.php index 8c6b6f0..5d35d7e 100644 --- a/src/Printers/HtmlDump.php +++ b/src/Printers/HtmlDump.php @@ -27,7 +27,7 @@ class HtmlDump implements IPrinter private $index; - public function printIntro($mode) + public function printIntro(string $mode): void { if ($mode === Runner::MODE_RESET) { $this->output(' RESET: All tables, views and data has been destroyed!'); @@ -37,7 +37,7 @@ public function printIntro($mode) } - public function printToExecute(array $toExecute) + public function printToExecute(array $toExecute): void { if ($toExecute) { $this->output(' ' . count($toExecute) . ' migrations need to be executed.'); @@ -50,9 +50,9 @@ public function printToExecute(array $toExecute) } - public function printExecute(File $file, $count, $time) + public function printExecute(File $file, int $count, float $time): void { - $format = '%0' . strlen($this->count) . 'd'; + $format = '%0' . strlen((string) $this->count) . 'd'; $name = htmlspecialchars($file->group->name . '/' . $file->name); $this->output(sprintf( $format . '/' . $format . ': %s (%d %s, %0.3f s)', @@ -61,31 +61,26 @@ public function printExecute(File $file, $count, $time) } - public function printDone() + public function printDone(): void { $this->output('OK', 'success'); } - public function printError(Exception $e) + public function printError(Exception $e): void { $this->output('ERROR: ' . htmlspecialchars($e->getMessage()), 'error'); throw $e; } - public function printSource($code) + public function printSource(string $code): void { $this->output($code); } - /** - * @param string $s HTML string - * @param string $class - * @return void - */ - protected function output($s, $class = 'info') + protected function output(string $s, string $class = 'info'): void { echo "
    $s
    \n"; } diff --git a/src/exceptions.php b/src/exceptions.php index 903bbe7..3fa3034 100644 --- a/src/exceptions.php +++ b/src/exceptions.php @@ -9,11 +9,13 @@ namespace Nextras\Migrations; +use Throwable; + /** * Marker interface. */ -interface Exception +interface Exception extends Throwable { } diff --git a/tests/cases/integration/dbal/Runner.EmptyRun.phpt b/tests/cases/integration/dbal/Runner.EmptyRun.phpt index 5bc1c7e..255182c 100644 --- a/tests/cases/integration/dbal/Runner.EmptyRun.phpt +++ b/tests/cases/integration/dbal/Runner.EmptyRun.phpt @@ -15,7 +15,7 @@ require __DIR__ . '/../../../bootstrap.php'; class EmptyRunTest extends IntegrationTestCase { - public function testReset() + public function testReset(): void { $this->runner->run(Runner::MODE_RESET); Assert::same([ @@ -29,7 +29,7 @@ class EmptyRunTest extends IntegrationTestCase } - protected function getGroups($dir) + protected function getGroups(string $dir): array { return []; } diff --git a/tests/cases/integration/dbal/Runner.FirstRun.phpt b/tests/cases/integration/dbal/Runner.FirstRun.phpt index 2051f11..dc54197 100644 --- a/tests/cases/integration/dbal/Runner.FirstRun.phpt +++ b/tests/cases/integration/dbal/Runner.FirstRun.phpt @@ -16,7 +16,7 @@ require __DIR__ . '/../../../bootstrap.php'; class FirstRunTest extends IntegrationTestCase { - public function testReset() + public function testReset(): void { $this->runner->run(Runner::MODE_RESET); Assert::same([ @@ -54,7 +54,7 @@ class FirstRunTest extends IntegrationTestCase } - public function testContinue() + public function testContinue(): void { $this->runner->run(Runner::MODE_CONTINUE); Assert::same([ @@ -92,7 +92,7 @@ class FirstRunTest extends IntegrationTestCase } - public function testInit() + public function testInit(): void { $options = Tester\Environment::loadData(); $this->runner->run(Runner::MODE_INIT); diff --git a/tests/cases/integration/dbal/Runner.SecondRun.phpt b/tests/cases/integration/dbal/Runner.SecondRun.phpt index 0756b62..c0c5947 100644 --- a/tests/cases/integration/dbal/Runner.SecondRun.phpt +++ b/tests/cases/integration/dbal/Runner.SecondRun.phpt @@ -17,7 +17,7 @@ require __DIR__ . '/../../../bootstrap.php'; class SecondRunTest extends IntegrationTestCase { - public function testReset() + public function testReset(): void { $this->driver->loadFile($this->fixtureDir . '/3ok.sql'); Assert::count(3, $this->driver->getAllMigrations()); @@ -39,7 +39,7 @@ class SecondRunTest extends IntegrationTestCase } - public function testContinueOk() + public function testContinueOk(): void { $this->driver->loadFile($this->fixtureDir . '/3ok.sql'); Assert::count(3, $this->driver->getAllMigrations()); @@ -58,7 +58,7 @@ class SecondRunTest extends IntegrationTestCase } - public function testContinueError() + public function testContinueError(): void { $this->driver->loadFile($this->fixtureDir . '/2ok, 1ko.sql'); Assert::count(3, $this->driver->getAllMigrations()); @@ -77,7 +77,7 @@ class SecondRunTest extends IntegrationTestCase } - public function testInit() + public function testInit(): void { $options = Tester\Environment::loadData(); $this->driver->loadFile($this->fixtureDir . '/3ok.sql'); diff --git a/tests/cases/integration/nette-di/MigrationsExtension.phpt b/tests/cases/integration/nette-di/MigrationsExtension.phpt index 0167527..80cb5d1 100644 --- a/tests/cases/integration/nette-di/MigrationsExtension.phpt +++ b/tests/cases/integration/nette-di/MigrationsExtension.phpt @@ -21,7 +21,7 @@ class MigrationsExtensionTest extends TestCase /** * @dataProvider provideCommandsData */ - public function testCommands($config) + public function testCommands(string $config): void { $dic = $this->createContainer($config); @@ -31,7 +31,7 @@ class MigrationsExtensionTest extends TestCase } - public function provideCommandsData() + public function provideCommandsData(): array { return [ ['configA'], @@ -47,7 +47,7 @@ class MigrationsExtensionTest extends TestCase /** * @dataProvider provideDiffGeneratorData */ - public function testDoctrineDiffGenerator($config) + public function testDoctrineDiffGenerator(string $config): void { $dic = $this->createContainer($config); @@ -62,7 +62,7 @@ class MigrationsExtensionTest extends TestCase } - public function provideDiffGeneratorData() + public function provideDiffGeneratorData(): array { return [ ['diffGenerator.configA'], @@ -71,7 +71,7 @@ class MigrationsExtensionTest extends TestCase } - public function testDynamicContainerParameters() + public function testDynamicContainerParameters(): void { if (!method_exists(Nette\DI\Compiler::class, 'setDynamicParameterNames')) { Environment::skip('Required Nette >= 2.4.7'); @@ -89,7 +89,7 @@ class MigrationsExtensionTest extends TestCase } - public function testOptionsAsService() + public function testOptionsAsService(): void { $container = $this->createContainer('optionsAsService'); @@ -100,7 +100,7 @@ class MigrationsExtensionTest extends TestCase } - public function testMultipleRegistrations() + public function testMultipleRegistrations(): void { $container = $this->createContainer('multipleRegistrations'); @@ -113,11 +113,7 @@ class MigrationsExtensionTest extends TestCase } - /** - * @param string $config - * @return Nette\DI\Container - */ - protected function createContainer($config, array $dynamicParameters = null) + protected function createContainer(string $config, array $dynamicParameters = null): Nette\DI\Container { $options = parse_ini_file(__DIR__ . '/../../../drivers.ini', true)['mysql']; diff --git a/tests/cases/integration/symfony-bundle/SymfonyBundleTest.phpt b/tests/cases/integration/symfony-bundle/SymfonyBundleTest.phpt index 15621af..2af253b 100644 --- a/tests/cases/integration/symfony-bundle/SymfonyBundleTest.phpt +++ b/tests/cases/integration/symfony-bundle/SymfonyBundleTest.phpt @@ -24,7 +24,7 @@ class SymfonyBundleTest extends TestCase private $symfonyKernel; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -48,7 +48,7 @@ class SymfonyBundleTest extends TestCase } - public function testMigrationsReset() + public function testMigrationsReset(): void { $application = new Application($this->symfonyKernel); @@ -58,7 +58,7 @@ class SymfonyBundleTest extends TestCase } - public function testMigrationsContinue() + public function testMigrationsContinue(): void { $application = new Application($this->symfonyKernel); diff --git a/tests/cases/unit/BaseDriverTest.phpt b/tests/cases/unit/BaseDriverTest.phpt index 3ebfa19..1623d5f 100644 --- a/tests/cases/unit/BaseDriverTest.phpt +++ b/tests/cases/unit/BaseDriverTest.phpt @@ -19,7 +19,7 @@ class BaseDriverTest extends Tester\TestCase /** * @dataProvider provideLoadFileData */ - public function testLoadFile($content, array $expectedQueries) + public function testLoadFile(string $content, array $expectedQueries): void { $dbal = Mockery::mock(Nextras\Migrations\IDbal::class); $dbal->shouldReceive('escapeIdentifier')->with('migrations')->andReturn('migrations'); @@ -38,7 +38,7 @@ class BaseDriverTest extends Tester\TestCase } - protected function provideLoadFileData() + protected function provideLoadFileData(): array { return [ [ diff --git a/tests/cases/unit/CreateCommandTest.phpt b/tests/cases/unit/CreateCommandTest.phpt index cb3da98..70065d3 100644 --- a/tests/cases/unit/CreateCommandTest.phpt +++ b/tests/cases/unit/CreateCommandTest.phpt @@ -18,7 +18,7 @@ require __DIR__ . '/../../bootstrap.php'; class CreateCommandTest extends Tester\TestCase { - public function testTypeArgDescription() + public function testTypeArgDescription(): void { $driver = Mockery::mock(Nextras\Migrations\IDriver::class); $config = new DefaultConfiguration('migrations', $driver); diff --git a/tests/cases/unit/Finder.logicalName.phpt b/tests/cases/unit/Finder.logicalName.phpt index fcf1c9d..7b125c6 100644 --- a/tests/cases/unit/Finder.logicalName.phpt +++ b/tests/cases/unit/Finder.logicalName.phpt @@ -22,11 +22,11 @@ class FinderLogicalNameTest extends Tester\TestCase /** @var Finder|Mockery\MockInterface */ private $finder; - /** @var Group[] */ + /** @var list */ private $groups; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->finder = Mockery::mock(Nextras\Migrations\Engine\Finder::class) @@ -44,7 +44,7 @@ class FinderLogicalNameTest extends Tester\TestCase } - public function testSimple() + public function testSimple(): void { $this->finder->shouldReceive('getItems') ->with('./baseDir/structures') @@ -62,7 +62,7 @@ class FinderLogicalNameTest extends Tester\TestCase } - public function testComplex() + public function testComplex(): void { $this->finder->shouldReceive('getItems') ->with('./baseDir/structures') diff --git a/tests/cases/unit/OrderResolverTest.phpt b/tests/cases/unit/OrderResolverTest.phpt index 619b6b4..44af898 100644 --- a/tests/cases/unit/OrderResolverTest.phpt +++ b/tests/cases/unit/OrderResolverTest.phpt @@ -21,7 +21,7 @@ require __DIR__ . '/../../bootstrap.php'; class OrderResolverTest extends Tester\TestCase { - public function testFirstRun() + public function testFirstRun(): void { $resolver = new OrderResolver; @@ -39,7 +39,7 @@ class OrderResolverTest extends Tester\TestCase } - public function testFirstRunTwoGroups() + public function testFirstRunTwoGroups(): void { $resolver = new OrderResolver; @@ -59,7 +59,7 @@ class OrderResolverTest extends Tester\TestCase } - public function testSecondRunContinue() + public function testSecondRunContinue(): void { $resolver = new OrderResolver; @@ -78,7 +78,7 @@ class OrderResolverTest extends Tester\TestCase } - public function testSecondRunContinueNothingToDo() + public function testSecondRunContinueNothingToDo(): void { $resolver = new OrderResolver; @@ -98,7 +98,7 @@ class OrderResolverTest extends Tester\TestCase } - public function testSecondRunContinueTwoGroups() + public function testSecondRunContinueTwoGroups(): void { $resolver = new OrderResolver; @@ -123,7 +123,7 @@ class OrderResolverTest extends Tester\TestCase } - public function testSecondRunContinueDisabledGroup() + public function testSecondRunContinueDisabledGroup(): void { $resolver = new OrderResolver; @@ -146,7 +146,7 @@ class OrderResolverTest extends Tester\TestCase } - public function testSecondRunReset() + public function testSecondRunReset(): void { $resolver = new OrderResolver; @@ -164,7 +164,7 @@ class OrderResolverTest extends Tester\TestCase } - public function testRunWithDisabledGroups() + public function testRunWithDisabledGroups(): void { $groupA = $this->createGroup('structures'); $groupB = $this->createGroup('data', false, ['structures']); @@ -181,7 +181,7 @@ class OrderResolverTest extends Tester\TestCase } - public function testTopologicalOrder() + public function testTopologicalOrder(): void { $resolver = new OrderResolver(); @@ -200,7 +200,7 @@ class OrderResolverTest extends Tester\TestCase } - public function testIndependentGroupsOrder1() + public function testIndependentGroupsOrder1(): void { $resolver = new OrderResolver(); @@ -222,7 +222,7 @@ class OrderResolverTest extends Tester\TestCase } - public function testIndependentGroupsOrder2() + public function testIndependentGroupsOrder2(): void { $resolver = new OrderResolver(); @@ -247,7 +247,7 @@ class OrderResolverTest extends Tester\TestCase } - public function testErrorRemovedFile() + public function testErrorRemovedFile(): void { $resolver = new OrderResolver; @@ -267,7 +267,7 @@ class OrderResolverTest extends Tester\TestCase } - public function testErrorChangedChecksum() + public function testErrorChangedChecksum(): void { $resolver = new OrderResolver; @@ -288,7 +288,7 @@ class OrderResolverTest extends Tester\TestCase } - public function testErrorIncompleteMigration() + public function testErrorIncompleteMigration(): void { $resolver = new OrderResolver; @@ -309,7 +309,7 @@ class OrderResolverTest extends Tester\TestCase } - public function testErrorNewMigrationInTheMiddleOfExistingOnes() + public function testErrorNewMigrationInTheMiddleOfExistingOnes(): void { $resolver = new OrderResolver; @@ -332,7 +332,7 @@ class OrderResolverTest extends Tester\TestCase } - public function testErrorNewMigrationInTheMiddleOfExistingOnes2() + public function testErrorNewMigrationInTheMiddleOfExistingOnes2(): void { $resolver = new OrderResolver(); @@ -359,7 +359,7 @@ class OrderResolverTest extends Tester\TestCase } - public function testErrorNewMigrationInTheMiddleOfExistingOnes3() + public function testErrorNewMigrationInTheMiddleOfExistingOnes3(): void { $resolver = new OrderResolver(); @@ -385,7 +385,7 @@ class OrderResolverTest extends Tester\TestCase } - public function testErrorMigrationDependingOnUnknownGroup() + public function testErrorMigrationDependingOnUnknownGroup(): void { $resolver = new OrderResolver; @@ -402,7 +402,7 @@ class OrderResolverTest extends Tester\TestCase } - public function testErrorGroupDependingOnUnknownGroup() + public function testErrorGroupDependingOnUnknownGroup(): void { $resolver = new OrderResolver; @@ -419,7 +419,7 @@ class OrderResolverTest extends Tester\TestCase } - public function testErrorDisablingRequiredGroup() + public function testErrorDisablingRequiredGroup(): void { $resolver = new OrderResolver; @@ -437,7 +437,7 @@ class OrderResolverTest extends Tester\TestCase } - public function testErrorAmbiguousLogicalName() + public function testErrorAmbiguousLogicalName(): void { $resolver = new OrderResolver(); @@ -458,7 +458,7 @@ class OrderResolverTest extends Tester\TestCase } - public function testErrorAmbiguousLogicalNameCyclic() + public function testErrorAmbiguousLogicalNameCyclic(): void { $resolver = new OrderResolver(); @@ -479,28 +479,31 @@ class OrderResolverTest extends Tester\TestCase } - private function createMigration($groupName, $fileName, $checksum = null, $completed = true) + private function createMigration(string $groupName, string $fileName, ?string $checksum = null, bool $completed = true): Migration { $migration = new Migration; $migration->group = $groupName; $migration->filename = $fileName; - $migration->checksum = $checksum ?: "$fileName.md5"; + $migration->checksum = $checksum ?? "$fileName.md5"; $migration->completed = $completed; return $migration; } - private function createFile($name, $group, $checksum = null) + private function createFile(string $name, Group $group, ?string $checksum = null): File { $file = new File; $file->name = $name; $file->group = $group; - $file->checksum = $checksum ?: "$name.md5"; + $file->checksum = $checksum ?? "$name.md5"; return $file; } - private function createGroup($name, $enabled = true, $deps = []) + /** + * @param list $deps + */ + private function createGroup(string $name, bool $enabled = true, array $deps = []): Group { $group = new Group; $group->name = $name; diff --git a/tests/inc/IntegrationTestCase.php b/tests/inc/IntegrationTestCase.php index 5d2e420..f68e152 100644 --- a/tests/inc/IntegrationTestCase.php +++ b/tests/inc/IntegrationTestCase.php @@ -40,7 +40,7 @@ abstract class IntegrationTestCase extends TestCase protected $fixtureDir; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -72,7 +72,7 @@ protected function setUp() } - protected function tearDown() + protected function tearDown(): void { parent::tearDown(); $cleanupDb = require $this->fixtureDir . '/cleanup.php'; @@ -81,7 +81,10 @@ protected function tearDown() } - protected function getGroups($dir) + /** + * @return list + */ + protected function getGroups(string $dir): array { $structures = new Group(); $structures->enabled = true; @@ -106,9 +109,9 @@ protected function getGroups($dir) /** - * @return array (extension => IExtensionHandler) + * @return array (extension => IExtensionHandler) */ - protected function getExtensionHandlers() + protected function getExtensionHandlers(): array { return [ 'sql' => new Nextras\Migrations\Extensions\SqlHandler($this->driver), @@ -117,11 +120,9 @@ protected function getExtensionHandlers() /** - * @param array $options - * @return IDbal * @throws \Exception */ - protected function createDbal($options) + protected function createDbal(array $options): IDbal { switch ($options['dbal']) { case 'dibi': @@ -178,12 +179,7 @@ protected function createDbal($options) } - /** - * @param array $name - * @param IDbal $dbal - * @return IDriver - */ - protected function createDriver($name, IDbal $dbal) + protected function createDriver(string $name, IDbal $dbal): IDriver { switch ($name) { case 'mysql': @@ -191,14 +187,14 @@ protected function createDriver($name, IDbal $dbal) case 'pgsql': return new Nextras\Migrations\Drivers\PgSqlDriver($dbal, 'm', $this->dbName); + + default: + throw new \Exception("Unknown driver '$name'."); } } - /** - * @return IPrinter - */ - protected function createPrinter() + protected function createPrinter(): IPrinter { return new TestPrinter(); } diff --git a/tests/inc/TestPrinter.php b/tests/inc/TestPrinter.php index cdcf405..a1abf8e 100644 --- a/tests/inc/TestPrinter.php +++ b/tests/inc/TestPrinter.php @@ -7,7 +7,7 @@ class TestPrinter extends Console { - /** @var string[] output lines */ + /** @var list output lines */ public $lines = []; /** @var string whole output */ @@ -21,7 +21,7 @@ public function __construct() } - protected function output($s, $color = NULL) + protected function output(string $s, string $color = null): void { $this->lines[] = preg_replace('#; \d+\.\d+ s#', '; XX s', $s); $this->out .= "$s\n"; diff --git a/tests/inc/TestSymfonyKernel.php b/tests/inc/TestSymfonyKernel.php index 9d93629..7a92c11 100644 --- a/tests/inc/TestSymfonyKernel.php +++ b/tests/inc/TestSymfonyKernel.php @@ -20,11 +20,7 @@ class TestSymfonyKernel extends Kernel private $parameters; - /** - * @param string $configPath - * @param array $parameters - */ - public function __construct($configPath, array $parameters) + public function __construct(string $configPath, array $parameters) { parent::__construct('dev', true); @@ -33,13 +29,13 @@ public function __construct($configPath, array $parameters) } - public function getRootDir() + public function getRootDir(): string { return TEMP_DIR . '/symfony-bundle'; } - public function registerBundles() + public function registerBundles(): array { return [ new FrameworkBundle(), @@ -49,9 +45,9 @@ public function registerBundles() } - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { - $loader->load(function (ContainerBuilder $container) { + $loader->load(function (ContainerBuilder $container): void { $container->addResource(new ContainerParametersResource($this->parameters)); foreach ($this->parameters as $key => $value) { $container->setParameter($key, $value); diff --git a/tests/inc/TestSymfonyKernel6.php b/tests/inc/TestSymfonyKernel6.php index 3e78f82..f95a6c3 100644 --- a/tests/inc/TestSymfonyKernel6.php +++ b/tests/inc/TestSymfonyKernel6.php @@ -21,10 +21,9 @@ class TestSymfonyKernel6 extends Kernel /** - * @param string $configPath * @param array $parameters */ - public function __construct($configPath, array $parameters) + public function __construct(string $configPath, array $parameters) { parent::__construct('dev', true); @@ -33,7 +32,7 @@ public function __construct($configPath, array $parameters) } - public function getRootDir() + public function getRootDir(): string { return TEMP_DIR . '/symfony-bundle'; } @@ -49,9 +48,9 @@ public function registerBundles(): iterable } - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { - $loader->load(function (ContainerBuilder $container) { + $loader->load(function (ContainerBuilder $container): void { $container->addResource(new ContainerParametersResource($this->parameters)); foreach ($this->parameters as $key => $value) { $container->setParameter($key, $value); From da67747e84a50f159e6b2c81548c4276253439ed Mon Sep 17 00:00:00 2001 From: Jan Tvrdik Date: Sun, 20 Dec 2020 16:05:23 +0100 Subject: [PATCH 12/12] MigrationsExtension: replace deprecated setClass() with setType() --- src/Bridges/NetteDI/MigrationsExtension.php | 22 ++++++++++----------- tests/matrix/nette-di/nette-2.4-php-7.1.sh | 2 +- tests/matrix/nette-di/nette-2.4-php-7.2.sh | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Bridges/NetteDI/MigrationsExtension.php b/src/Bridges/NetteDI/MigrationsExtension.php index c837f07..004916c 100644 --- a/src/Bridges/NetteDI/MigrationsExtension.php +++ b/src/Bridges/NetteDI/MigrationsExtension.php @@ -173,7 +173,7 @@ private function getDbalDefinition($dbal) if ($factory) { return $this->getContainerBuilder() ->addDefinition($this->prefix('dbal')) - ->setClass(Nextras\Migrations\IDbal::class) + ->setType(Nextras\Migrations\IDbal::class) ->setFactory($factory); } elseif ($dbal === null) { @@ -218,7 +218,7 @@ private function getDriverDefinition($driver, $dbal) if ($factory) { return $this->getContainerBuilder() ->addDefinition($this->prefix('driver')) - ->setClass(Nextras\Migrations\IDriver::class) + ->setType(Nextras\Migrations\IDriver::class) ->setFactory($factory); } elseif ($driver === null) { @@ -260,7 +260,7 @@ private function getPrinterDefinition($printer) if ($factory) { return $this->getContainerBuilder() ->addDefinition($this->prefix('printer')) - ->setClass(Nextras\Migrations\IPrinter::class) + ->setType(Nextras\Migrations\IPrinter::class) ->setFactory($factory); } elseif ($printer === null) { @@ -358,7 +358,7 @@ private function createGroupDefinitions(array $groups): array $groupDefinitions[] = $builder->addDefinition($this->prefix("group.$serviceName")) ->addTag(self::TAG_GROUP, ['for' => [$this->name]]) ->setAutowired(false) - ->setClass(Nextras\Migrations\Entities\Group::class) + ->setType(Nextras\Migrations\Entities\Group::class) ->addSetup('$name', [$groupName]) ->addSetup('$enabled', [$enabled]) ->addSetup('$directory', [$directory]) @@ -382,12 +382,12 @@ private function createExtensionHandlerDefinitions($driver, array $phpParams): a $sqlHandler = $builder->addDefinition($this->prefix('extensionHandler.sql')) ->addTag(self::TAG_EXTENSION_HANDLER, ['for' => [$this->name], 'extension' => 'sql']) ->setAutowired(false) - ->setClass(Nextras\Migrations\Extensions\SqlHandler::class) + ->setType(Nextras\Migrations\Extensions\SqlHandler::class) ->setArguments([$driver]); $phpHandler = $builder->addDefinition($this->prefix('extensionHandler.php')) ->addTag(self::TAG_EXTENSION_HANDLER, ['for' => [$this->name], 'extension' => 'php']) - ->setClass(Nextras\Migrations\Extensions\PhpHandler::class) + ->setType(Nextras\Migrations\Extensions\PhpHandler::class) ->setAutowired(false) ->setArguments([$phpParams]); @@ -399,7 +399,7 @@ private function createConfigurationDefinition(): ServiceDefinition { return $this->getContainerBuilder() ->addDefinition($this->prefix('configuration')) - ->setClass(Nextras\Migrations\IConfiguration::class) + ->setType(Nextras\Migrations\IConfiguration::class) ->setFactory(Nextras\Migrations\Configurations\Configuration::class); } @@ -410,7 +410,7 @@ private function createDoctrineStructureDiffGeneratorDefinition(?string $ignored return $builder->addDefinition($this->prefix('diffGenerator.structures')) ->setAutowired(false) - ->setClass(Nextras\Migrations\IDiffGenerator::class) + ->setType(Nextras\Migrations\IDiffGenerator::class) ->setFactory(Nextras\Migrations\Bridges\DoctrineOrm\StructureDiffGenerator::class) ->setArguments(['@Doctrine\ORM\EntityManagerInterface', $ignoredQueriesFile]); } @@ -427,17 +427,17 @@ private function createSymfonyCommandDefinitions($driver, $configuration, $print $builder->addExcludedClasses([Nextras\Migrations\Bridges\SymfonyConsole\BaseCommand::class]); $builder->addDefinition($this->prefix('continueCommand')) - ->setClass(Nextras\Migrations\Bridges\SymfonyConsole\ContinueCommand::class) + ->setType(Nextras\Migrations\Bridges\SymfonyConsole\ContinueCommand::class) ->setArguments([$driver, $configuration, $printer]) ->addTag('kdyby.console.command'); $builder->addDefinition($this->prefix('createCommand')) - ->setClass(Nextras\Migrations\Bridges\SymfonyConsole\CreateCommand::class) + ->setType(Nextras\Migrations\Bridges\SymfonyConsole\CreateCommand::class) ->setArguments([$driver, $configuration, $printer]) ->addTag('kdyby.console.command'); $builder->addDefinition($this->prefix('resetCommand')) - ->setClass(Nextras\Migrations\Bridges\SymfonyConsole\ResetCommand::class) + ->setType(Nextras\Migrations\Bridges\SymfonyConsole\ResetCommand::class) ->setArguments([$driver, $configuration, $printer]) ->addTag('kdyby.console.command'); } diff --git a/tests/matrix/nette-di/nette-2.4-php-7.1.sh b/tests/matrix/nette-di/nette-2.4-php-7.1.sh index 4b0efa5..0c427ec 100644 --- a/tests/matrix/nette-di/nette-2.4-php-7.1.sh +++ b/tests/matrix/nette-di/nette-2.4-php-7.1.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash PHP_VERSION_MIN="70100" PHP_VERSION_MAX="70199" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE nette/di:~2.4.1" +COMPOSER_REQUIRE="$COMPOSER_REQUIRE nette/di:~2.4.10" COMPOSER_REQUIRE="$COMPOSER_REQUIRE nette/utils:~2.4.0" COMPOSER_REQUIRE="$COMPOSER_REQUIRE dibi/dibi:~4.0" COMPOSER_REQUIRE="$COMPOSER_REQUIRE doctrine/dbal:~2.5" diff --git a/tests/matrix/nette-di/nette-2.4-php-7.2.sh b/tests/matrix/nette-di/nette-2.4-php-7.2.sh index b9f9c3e..16d1cfd 100644 --- a/tests/matrix/nette-di/nette-2.4-php-7.2.sh +++ b/tests/matrix/nette-di/nette-2.4-php-7.2.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash PHP_VERSION_MIN="70200" PHP_VERSION_MAX="70299" -COMPOSER_REQUIRE="$COMPOSER_REQUIRE nette/di:~2.4.7" +COMPOSER_REQUIRE="$COMPOSER_REQUIRE nette/di:~2.4.10" COMPOSER_REQUIRE="$COMPOSER_REQUIRE nette/utils:~2.4.5" COMPOSER_REQUIRE="$COMPOSER_REQUIRE dibi/dibi:~4.0" COMPOSER_REQUIRE="$COMPOSER_REQUIRE doctrine/dbal:~2.5"