From 6d1bf4ca611dd07c8146d6b076395efed80a6d11 Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Fri, 27 Dec 2019 16:33:38 +0100 Subject: [PATCH] Update to doctrine/coding-standard v7 --- bin/doctrine-migrations.php | 4 +- composer.json | 2 +- composer.lock | 55 ++++++++++--------- .../Configuration/Configuration.php | 1 + .../Configuration/FormattedFile.php | 2 +- .../Configuration/Configuration/JsonFile.php | 2 +- .../Configuration/Configuration/PhpFile.php | 1 + .../Configuration/Configuration/XmlFile.php | 6 +- .../Connection/ConfigurationFile.php | 1 + lib/Doctrine/Migrations/DbalMigrator.php | 2 +- lib/Doctrine/Migrations/DependencyFactory.php | 1 + .../Finder/Exception/NameIsReserved.php | 2 +- lib/Doctrine/Migrations/Finder/Finder.php | 2 +- .../Finder/RecursiveRegexFinder.php | 2 +- .../Migrations/Generator/Generator.php | 1 + .../Metadata/AvailableMigrationsList.php | 4 +- .../Metadata/ExecutedMigrationsSet.php | 5 +- .../Metadata/Storage/TableMetadataStorage.php | 9 ++- lib/Doctrine/Migrations/SchemaDumper.php | 11 ++-- .../Tools/Console/Command/DiffCommand.php | 4 +- .../Tools/Console/Command/DoctrineCommand.php | 1 + .../Console/Command/DumpSchemaCommand.php | 1 + .../Tools/Console/Command/GenerateCommand.php | 1 + .../Tools/Console/Command/MigrateCommand.php | 3 + .../Tools/Console/Command/StatusCommand.php | 2 + .../Tools/Console/Command/VersionCommand.php | 1 + .../Tools/Console/ConsoleRunner.php | 2 +- .../Helper/MigrationDirectoryHelper.php | 2 +- .../Helper/MigrationStatusInfosHelper.php | 4 ++ .../Version/DefaultAliasResolver.php | 4 ++ .../Version/SortedMigrationPlanCalculator.php | 1 + .../Configuration/JsonLoaderTest.php | 2 +- .../Configuration/LoaderTest.php | 2 +- .../Configuration/PhpLoaderTest.php | 2 +- .../Configuration/XmlLoaderTest.php | 2 +- .../Configuration/YamlLoaderTest.php | 2 +- .../Tests/Finder/RecursiveRegexFinderTest.php | 2 +- .../Helper/MigrationDirectoryHelperTest.php | 2 +- .../Tests/Version/AliasResolverTest.php | 2 + .../Migrations/Tests/Version/ExecutorTest.php | 2 + 40 files changed, 95 insertions(+), 62 deletions(-) diff --git a/bin/doctrine-migrations.php b/bin/doctrine-migrations.php index 8e2371b02c..aa4eabee75 100644 --- a/bin/doctrine-migrations.php +++ b/bin/doctrine-migrations.php @@ -6,11 +6,11 @@ use Doctrine\Migrations\Tools\Console\ConsoleRunner; use Phar; -use const PHP_EOL; -use const STDERR; use function extension_loaded; use function file_exists; use function fwrite; +use const PHP_EOL; +use const STDERR; (static function () : void { $autoloadFiles = [ diff --git a/composer.json b/composer.json index cd627e6098..2cf5895920 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ }, "require-dev": { "ext-pdo_sqlite": "*", - "doctrine/coding-standard": "^6.0", + "doctrine/coding-standard": "^7.0", "doctrine/orm": "^2.6", "jdorn/sql-formatter": "^1.1", "phpstan/phpstan": "^0.11", diff --git a/composer.lock b/composer.lock index 10a2fe0541..f0386da27c 100644 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "abc5cd73fc71405f367385fb9a1ce882", + "content-hash": "0a41fb82ffcaf0bb65df32323e85b7e8", "packages": [ { "name": "doctrine/cache", @@ -997,28 +997,28 @@ }, { "name": "doctrine/coding-standard", - "version": "6.0.0", + "version": "7.0.2", "source": { "type": "git", "url": "https://github.com/doctrine/coding-standard.git", - "reference": "d33f69eb98b25aa51ffe3a909f0ec77000af4701" + "reference": "d8a60ec4da68025c42795b714f66e277dd3e11de" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/coding-standard/zipball/d33f69eb98b25aa51ffe3a909f0ec77000af4701", - "reference": "d33f69eb98b25aa51ffe3a909f0ec77000af4701", + "url": "https://api.github.com/repos/doctrine/coding-standard/zipball/d8a60ec4da68025c42795b714f66e277dd3e11de", + "reference": "d8a60ec4da68025c42795b714f66e277dd3e11de", "shasum": "" }, "require": { "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0", - "php": "^7.1", - "slevomat/coding-standard": "^5.0", - "squizlabs/php_codesniffer": "^3.4.0" + "php": "^7.2", + "slevomat/coding-standard": "^6.0", + "squizlabs/php_codesniffer": "^3.5.3" }, "type": "phpcodesniffer-standard", "extra": { "branch-alias": { - "dev-master": "6.0.x-dev" + "dev-master": "7.0.x-dev" } }, "autoload": { @@ -1054,7 +1054,7 @@ "standard", "style" ], - "time": "2019-03-15T12:45:47+00:00" + "time": "2019-12-11T07:59:21+00:00" }, { "name": "doctrine/collections", @@ -4018,30 +4018,31 @@ }, { "name": "slevomat/coding-standard", - "version": "5.0.4", + "version": "6.0.5", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "287ac3347c47918c0bf5e10335e36197ea10894c" + "reference": "eaa0c35c6b88d146e7dfd3580c4d5fa9c49c7a23" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/287ac3347c47918c0bf5e10335e36197ea10894c", - "reference": "287ac3347c47918c0bf5e10335e36197ea10894c", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/eaa0c35c6b88d146e7dfd3580c4d5fa9c49c7a23", + "reference": "eaa0c35c6b88d146e7dfd3580c4d5fa9c49c7a23", "shasum": "" }, "require": { "php": "^7.1", - "phpstan/phpdoc-parser": "^0.3.1", - "squizlabs/php_codesniffer": "^3.4.1" + "phpstan/phpdoc-parser": "0.3.5 - 0.4.2", + "squizlabs/php_codesniffer": "^3.5.3" }, "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "0.5.0", "jakub-onderka/php-parallel-lint": "1.0.0", "phing/phing": "2.16.1", - "phpstan/phpstan": "0.11.4", - "phpstan/phpstan-phpunit": "0.11", - "phpstan/phpstan-strict-rules": "0.11", - "phpunit/phpunit": "8.0.5" + "phpstan/phpstan": "0.11.19|0.12", + "phpstan/phpstan-phpunit": "0.11.2|0.12", + "phpstan/phpstan-strict-rules": "0.11.1|0.12", + "phpunit/phpunit": "7.5.18|8.5.0" }, "type": "phpcodesniffer-standard", "autoload": { @@ -4054,20 +4055,20 @@ "MIT" ], "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", - "time": "2019-03-22T19:10:53+00:00" + "time": "2019-12-19T16:04:26+00:00" }, { "name": "squizlabs/php_codesniffer", - "version": "3.5.0", + "version": "3.5.3", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "0afebf16a2e7f1e434920fa976253576151effe9" + "reference": "557a1fc7ac702c66b0bbfe16ab3d55839ef724cb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/0afebf16a2e7f1e434920fa976253576151effe9", - "reference": "0afebf16a2e7f1e434920fa976253576151effe9", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/557a1fc7ac702c66b0bbfe16ab3d55839ef724cb", + "reference": "557a1fc7ac702c66b0bbfe16ab3d55839ef724cb", "shasum": "" }, "require": { @@ -4105,7 +4106,7 @@ "phpcs", "standards" ], - "time": "2019-09-26T23:12:26+00:00" + "time": "2019-12-04T04:46:47+00:00" }, { "name": "symfony/finder", diff --git a/lib/Doctrine/Migrations/Configuration/Configuration.php b/lib/Doctrine/Migrations/Configuration/Configuration.php index 8dc92fc744..e103082875 100644 --- a/lib/Doctrine/Migrations/Configuration/Configuration.php +++ b/lib/Doctrine/Migrations/Configuration/Configuration.php @@ -58,6 +58,7 @@ public function freeze() : void if (! $this->frozen) { $this->validate(); } + $this->frozen = true; } diff --git a/lib/Doctrine/Migrations/Configuration/Configuration/FormattedFile.php b/lib/Doctrine/Migrations/Configuration/Configuration/FormattedFile.php index e01fa12f43..77e8a663a3 100644 --- a/lib/Doctrine/Migrations/Configuration/Configuration/FormattedFile.php +++ b/lib/Doctrine/Migrations/Configuration/Configuration/FormattedFile.php @@ -5,9 +5,9 @@ namespace Doctrine\Migrations\Configuration\Configuration; use Doctrine\Migrations\Configuration\Configuration; -use const PATHINFO_EXTENSION; use function count; use function pathinfo; +use const PATHINFO_EXTENSION; /** * @internal diff --git a/lib/Doctrine/Migrations/Configuration/Configuration/JsonFile.php b/lib/Doctrine/Migrations/Configuration/Configuration/JsonFile.php index c17a0df1fb..eab8764f25 100644 --- a/lib/Doctrine/Migrations/Configuration/Configuration/JsonFile.php +++ b/lib/Doctrine/Migrations/Configuration/Configuration/JsonFile.php @@ -7,12 +7,12 @@ use Doctrine\Migrations\Configuration\Configuration; use Doctrine\Migrations\Configuration\Configuration\Exception\JsonNotValid; use Doctrine\Migrations\Configuration\Exception\FileNotFound; -use const JSON_ERROR_NONE; use function assert; use function file_exists; use function file_get_contents; use function json_decode; use function json_last_error; +use const JSON_ERROR_NONE; final class JsonFile extends ConfigurationFile { diff --git a/lib/Doctrine/Migrations/Configuration/Configuration/PhpFile.php b/lib/Doctrine/Migrations/Configuration/Configuration/PhpFile.php index f9ae812a6b..25e5f1dfe3 100644 --- a/lib/Doctrine/Migrations/Configuration/Configuration/PhpFile.php +++ b/lib/Doctrine/Migrations/Configuration/Configuration/PhpFile.php @@ -17,6 +17,7 @@ public function getConfiguration() : Configuration if (! file_exists($this->file)) { throw FileNotFound::new($this->file); } + $config = require $this->file; if ($config instanceof Configuration) { return $config; diff --git a/lib/Doctrine/Migrations/Configuration/Configuration/XmlFile.php b/lib/Doctrine/Migrations/Configuration/Configuration/XmlFile.php index 6bb9962098..1f9d4b6fd3 100644 --- a/lib/Doctrine/Migrations/Configuration/Configuration/XmlFile.php +++ b/lib/Doctrine/Migrations/Configuration/Configuration/XmlFile.php @@ -10,8 +10,6 @@ use Doctrine\Migrations\Tools\BooleanStringFormatter; use DOMDocument; use SimpleXMLElement; -use const DIRECTORY_SEPARATOR; -use const LIBXML_NOCDATA; use function assert; use function file_exists; use function file_get_contents; @@ -19,6 +17,8 @@ use function libxml_use_internal_errors; use function simplexml_load_string; use function strtr; +use const DIRECTORY_SEPARATOR; +use const LIBXML_NOCDATA; final class XmlFile extends ConfigurationFile { @@ -44,6 +44,7 @@ public function getConfiguration() : Configuration false ); } + if (isset($config['migrations_paths'])) { $config['migrations_paths'] = $this->getDirectoriesRelativeToFile( $config['migrations_paths'], @@ -66,6 +67,7 @@ private function extractParameters(SimpleXMLElement $root, bool $loopOverNodes) if (! ($itemsToCheck instanceof SimpleXMLElement)) { return $config; } + foreach ($itemsToCheck as $node) { $nodeName = strtr($node->getName(), '-', '_'); if ($nodeName === 'migrations_paths') { diff --git a/lib/Doctrine/Migrations/Configuration/Connection/ConfigurationFile.php b/lib/Doctrine/Migrations/Configuration/Connection/ConfigurationFile.php index d53c25e4ed..af5585f2ac 100644 --- a/lib/Doctrine/Migrations/Configuration/Connection/ConfigurationFile.php +++ b/lib/Doctrine/Migrations/Configuration/Connection/ConfigurationFile.php @@ -43,6 +43,7 @@ public function getConnection() : Connection if (is_array($params)) { return DriverManager::getConnection($params); } + throw InvalidConfiguration::invalidArrayConfiguration(); } } diff --git a/lib/Doctrine/Migrations/DbalMigrator.php b/lib/Doctrine/Migrations/DbalMigrator.php index 6294540aa0..c884f061f6 100644 --- a/lib/Doctrine/Migrations/DbalMigrator.php +++ b/lib/Doctrine/Migrations/DbalMigrator.php @@ -11,8 +11,8 @@ use Psr\Log\LoggerInterface; use Symfony\Component\Stopwatch\StopwatchEvent; use Throwable; -use const COUNT_RECURSIVE; use function count; +use const COUNT_RECURSIVE; /** * The DbalMigrator class is responsible for generating and executing the SQL for a migration. diff --git a/lib/Doctrine/Migrations/DependencyFactory.php b/lib/Doctrine/Migrations/DependencyFactory.php index 35a23700a3..d0a44f42ac 100644 --- a/lib/Doctrine/Migrations/DependencyFactory.php +++ b/lib/Doctrine/Migrations/DependencyFactory.php @@ -160,6 +160,7 @@ public function getEntityManager() : EntityManagerInterface if ($this->emLoader === null) { throw MissingDependency::noEntityManager(); } + $this->em = $this->emLoader->getEntityManager(); } diff --git a/lib/Doctrine/Migrations/Finder/Exception/NameIsReserved.php b/lib/Doctrine/Migrations/Finder/Exception/NameIsReserved.php index 4f14128113..48eab127f8 100644 --- a/lib/Doctrine/Migrations/Finder/Exception/NameIsReserved.php +++ b/lib/Doctrine/Migrations/Finder/Exception/NameIsReserved.php @@ -5,8 +5,8 @@ namespace Doctrine\Migrations\Finder\Exception; use InvalidArgumentException; -use const PHP_EOL; use function sprintf; +use const PHP_EOL; final class NameIsReserved extends InvalidArgumentException implements FinderException { diff --git a/lib/Doctrine/Migrations/Finder/Finder.php b/lib/Doctrine/Migrations/Finder/Finder.php index 42a37bed8b..6d9464c4e6 100644 --- a/lib/Doctrine/Migrations/Finder/Finder.php +++ b/lib/Doctrine/Migrations/Finder/Finder.php @@ -7,7 +7,6 @@ use Doctrine\Migrations\Finder\Exception\InvalidDirectory; use Doctrine\Migrations\Finder\Exception\NameIsReserved; use ReflectionClass; -use const SORT_STRING; use function assert; use function get_declared_classes; use function in_array; @@ -16,6 +15,7 @@ use function realpath; use function strlen; use function strncmp; +use const SORT_STRING; /** * The Finder class is responsible for for finding migrations on disk at a given path. diff --git a/lib/Doctrine/Migrations/Finder/RecursiveRegexFinder.php b/lib/Doctrine/Migrations/Finder/RecursiveRegexFinder.php index 5b162af83c..03a36a9d7b 100644 --- a/lib/Doctrine/Migrations/Finder/RecursiveRegexFinder.php +++ b/lib/Doctrine/Migrations/Finder/RecursiveRegexFinder.php @@ -8,8 +8,8 @@ use RecursiveDirectoryIterator; use RecursiveIteratorIterator; use RegexIterator; -use const DIRECTORY_SEPARATOR; use function sprintf; +use const DIRECTORY_SEPARATOR; /** * The RecursiveRegexFinder class recursively searches the given directory for migrations. diff --git a/lib/Doctrine/Migrations/Generator/Generator.php b/lib/Doctrine/Migrations/Generator/Generator.php index 1854f8065d..de83a6a886 100644 --- a/lib/Doctrine/Migrations/Generator/Generator.php +++ b/lib/Doctrine/Migrations/Generator/Generator.php @@ -82,6 +82,7 @@ public function generateMigration( if (preg_match('~(.*)\\\\([^\\\\]+)~', $fqcn, $mch) === 0) { throw new InvalidArgumentException(sprintf('Invalid FQCN')); } + [$fqcn, $namespace, $className] = $mch; $dirs = $this->configuration->getMigrationDirectories(); diff --git a/lib/Doctrine/Migrations/Metadata/AvailableMigrationsList.php b/lib/Doctrine/Migrations/Metadata/AvailableMigrationsList.php index b375e2c0dd..1d70c1e5b4 100644 --- a/lib/Doctrine/Migrations/Metadata/AvailableMigrationsList.php +++ b/lib/Doctrine/Migrations/Metadata/AvailableMigrationsList.php @@ -35,7 +35,7 @@ public function getItems() : array public function getFirst(int $offset = 0) : AvailableMigration { if (! isset($this->items[$offset])) { - throw NoMigrationsFoundWithCriteria::new('first' . ($offset > 0 ? ('+' . $offset) : '')); + throw NoMigrationsFoundWithCriteria::new('first' . ($offset > 0 ? '+' . $offset : '')); } return $this->items[$offset]; @@ -45,7 +45,7 @@ public function getLast(int $offset = 0) : AvailableMigration { $offset = count($this->items) - 1 - (-1 * $offset); if (! isset($this->items[$offset])) { - throw NoMigrationsFoundWithCriteria::new('last' . ($offset > 0 ? ('+' . $offset) : '')); + throw NoMigrationsFoundWithCriteria::new('last' . ($offset > 0 ? '+' . $offset : '')); } return $this->items[$offset]; diff --git a/lib/Doctrine/Migrations/Metadata/ExecutedMigrationsSet.php b/lib/Doctrine/Migrations/Metadata/ExecutedMigrationsSet.php index 0a38419c6f..836be47fce 100644 --- a/lib/Doctrine/Migrations/Metadata/ExecutedMigrationsSet.php +++ b/lib/Doctrine/Migrations/Metadata/ExecutedMigrationsSet.php @@ -35,7 +35,7 @@ public function getItems() : array public function getFirst(int $offset = 0) : ExecutedMigration { if (! isset($this->items[$offset])) { - throw NoMigrationsFoundWithCriteria::new('first' . ($offset > 0 ? ('+' . $offset) : '')); + throw NoMigrationsFoundWithCriteria::new('first' . ($offset > 0 ? '+' . $offset : '')); } return $this->items[$offset]; @@ -45,7 +45,7 @@ public function getLast(int $offset = 0) : ExecutedMigration { $offset = count($this->items) - 1 - (-1 * $offset); if (! isset($this->items[$offset])) { - throw NoMigrationsFoundWithCriteria::new('last' . ($offset > 0 ? ('+' . $offset) : '')); + throw NoMigrationsFoundWithCriteria::new('last' . ($offset > 0 ? '+' . $offset : '')); } return $this->items[$offset]; @@ -74,6 +74,7 @@ public function getMigration(Version $version) : ExecutedMigration return $migration; } } + throw MigrationNotExecuted::new((string) $version); } } diff --git a/lib/Doctrine/Migrations/Metadata/Storage/TableMetadataStorage.php b/lib/Doctrine/Migrations/Metadata/Storage/TableMetadataStorage.php index 1e035450ee..ebf68b4961 100644 --- a/lib/Doctrine/Migrations/Metadata/Storage/TableMetadataStorage.php +++ b/lib/Doctrine/Migrations/Metadata/Storage/TableMetadataStorage.php @@ -22,7 +22,6 @@ use Doctrine\Migrations\Version\ExecutionResult; use Doctrine\Migrations\Version\Version; use InvalidArgumentException; -use const CASE_LOWER; use function array_change_key_case; use function floatval; use function round; @@ -30,6 +29,7 @@ use function strlen; use function strpos; use function strtolower; +use const CASE_LOWER; final class TableMetadataStorage implements MetadataStorage { @@ -61,6 +61,7 @@ public function __construct( if ($configuration !== null && ! ($configuration instanceof TableMetadataStorageConfiguration)) { throw new InvalidArgumentException(sprintf('%s accepts only %s as configuration', self::class, TableMetadataStorageConfiguration::class)); } + $this->configuration = $configuration ?: new TableMetadataStorageConfiguration(); } @@ -230,9 +231,7 @@ private function isAlreadyV3Format(AvailableMigration $availableMigration, Execu return strpos( (string) $availableMigration->getVersion(), (string) $executedMigration->getVersion() - ) !== ( - strlen((string) $availableMigration->getVersion()) - - strlen((string) $executedMigration->getVersion()) - ); + ) !== strlen((string) $availableMigration->getVersion()) - + strlen((string) $executedMigration->getVersion()); } } diff --git a/lib/Doctrine/Migrations/SchemaDumper.php b/lib/Doctrine/Migrations/SchemaDumper.php index 7f683f7f4e..952a65a676 100644 --- a/lib/Doctrine/Migrations/SchemaDumper.php +++ b/lib/Doctrine/Migrations/SchemaDumper.php @@ -11,11 +11,6 @@ use Doctrine\Migrations\Generator\Generator; use Doctrine\Migrations\Generator\SqlGenerator; use InvalidArgumentException; -use const PREG_BACKTRACK_LIMIT_ERROR; -use const PREG_BAD_UTF8_ERROR; -use const PREG_BAD_UTF8_OFFSET_ERROR; -use const PREG_INTERNAL_ERROR; -use const PREG_RECURSION_LIMIT_ERROR; use function array_merge; use function count; use function implode; @@ -24,6 +19,11 @@ use function restore_error_handler; use function set_error_handler; use function sprintf; +use const PREG_BACKTRACK_LIMIT_ERROR; +use const PREG_BAD_UTF8_ERROR; +use const PREG_BAD_UTF8_OFFSET_ERROR; +use const PREG_INTERNAL_ERROR; +use const PREG_RECURSION_LIMIT_ERROR; /** * The SchemaDumper class is responsible for dumping the current state of your database schema to a migration. This @@ -186,6 +186,7 @@ private static function pregMatch(string $pattern, string $subject, ?array &$mat default: $error = 'Error.'; } + throw new InvalidArgumentException($error); } diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php index de07c29efa..3d9de7f465 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php @@ -10,7 +10,6 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use const FILTER_VALIDATE_BOOLEAN; use function addslashes; use function assert; use function class_exists; @@ -18,6 +17,7 @@ use function is_string; use function key; use function sprintf; +use const FILTER_VALIDATE_BOOLEAN; /** * The DiffCommand class is responsible for generating a migration by comparing your current database schema to @@ -120,6 +120,7 @@ public function execute( } elseif (! isset($dirs[$namespace])) { throw new OutOfBoundsException(sprintf('Path not defined for the namespace %s', $namespace)); } + assert(is_string($namespace)); $fqcn = $this->getDependencyFactory()->getClassNameGenerator()->generateClassName($namespace); @@ -140,6 +141,7 @@ public function execute( return 0; } + throw $exception; } diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/DoctrineCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/DoctrineCommand.php index e23b4b972a..d722b09d87 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/DoctrineCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/DoctrineCommand.php @@ -40,6 +40,7 @@ protected function configure() : void if ($this->dependencyFactory !== null) { return; } + $this->addOption( 'configuration', null, diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/DumpSchemaCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/DumpSchemaCommand.php index 2a8c17b3e7..de4e3a31ab 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/DumpSchemaCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/DumpSchemaCommand.php @@ -103,6 +103,7 @@ public function execute( $dirs = $configuration->getMigrationDirectories(); $namespace = key($dirs); } + assert(is_string($namespace)); $this->checkNoPreviousDumpExistsForNamespace($namespace); diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/GenerateCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/GenerateCommand.php index c919518801..c5567710cf 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/GenerateCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/GenerateCommand.php @@ -66,6 +66,7 @@ public function execute(InputInterface $input, OutputInterface $output) : ?int } elseif (! isset($dirs[$namespace])) { throw new Exception(sprintf('Path not defined for the namespace %s', $namespace)); } + assert(is_string($namespace)); $fqcn = $this->getDependencyFactory()->getClassNameGenerator()->generateClassName($namespace); diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php index 3e7c374cdd..cac7bdac82 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php @@ -166,6 +166,7 @@ public function execute(InputInterface $input, OutputInterface $output) : ?int return 1; } + $writer = $this->getDependencyFactory()->getQueryWriter(); $writer->write($path, $plan->getDirection(), $sql); @@ -228,11 +229,13 @@ private function getVersionNameFromAlias( return; } + if ($versionAlias === 'next' || $versionAlias === 'latest') { $output->writeln('Already at latest version.'); return; } + if (substr($versionAlias, 0, 7) === 'current') { $output->writeln('The delta couldn\'t be reached.'); diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/StatusCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/StatusCommand.php index 00cc4ee964..7e9966867b 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/StatusCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/StatusCommand.php @@ -95,6 +95,7 @@ private function showUnavailableVersions(OutputInterface $output, ExecutedMigrat : null, ]); } + $table->render(); } @@ -128,6 +129,7 @@ private function showVersions( $description, ]); } + $table->render(); } } diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/VersionCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/VersionCommand.php index 34f84996a9..769421e0b0 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/VersionCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/VersionCommand.php @@ -157,6 +157,7 @@ private function markVersions(InputInterface $input, OutputInterface $output) : $this->mark($input, $output, $availableMigration->getVersion(), false, $executedMigrations); } } + foreach ($availableVersions->getItems() as $availableMigration) { $this->mark($input, $output, $availableMigration->getVersion(), true, $executedMigrations); } diff --git a/lib/Doctrine/Migrations/Tools/Console/ConsoleRunner.php b/lib/Doctrine/Migrations/Tools/Console/ConsoleRunner.php index 6809a4da50..bba5af2750 100644 --- a/lib/Doctrine/Migrations/Tools/Console/ConsoleRunner.php +++ b/lib/Doctrine/Migrations/Tools/Console/ConsoleRunner.php @@ -20,11 +20,11 @@ use PackageVersions\Versions; use RuntimeException; use Symfony\Component\Console\Application; -use const DIRECTORY_SEPARATOR; use function file_exists; use function getcwd; use function is_readable; use function sprintf; +use const DIRECTORY_SEPARATOR; /** * The ConsoleRunner class is used to create the Symfony Console application for the Doctrine Migrations console. diff --git a/lib/Doctrine/Migrations/Tools/Console/Helper/MigrationDirectoryHelper.php b/lib/Doctrine/Migrations/Tools/Console/Helper/MigrationDirectoryHelper.php index d3b74dc133..c050243011 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Helper/MigrationDirectoryHelper.php +++ b/lib/Doctrine/Migrations/Tools/Console/Helper/MigrationDirectoryHelper.php @@ -6,11 +6,11 @@ use Doctrine\Migrations\Configuration\Configuration; use Doctrine\Migrations\Tools\Console\Exception\DirectoryDoesNotExist; -use const DIRECTORY_SEPARATOR; use function date; use function file_exists; use function mkdir; use function rtrim; +use const DIRECTORY_SEPARATOR; /** * The MigrationDirectoryHelper class is responsible for returning the directory that migrations are stored in. diff --git a/lib/Doctrine/Migrations/Tools/Console/Helper/MigrationStatusInfosHelper.php b/lib/Doctrine/Migrations/Tools/Console/Helper/MigrationStatusInfosHelper.php index aad3f0ab7b..e0f05b8ca5 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Helper/MigrationStatusInfosHelper.php +++ b/lib/Doctrine/Migrations/Tools/Console/Helper/MigrationStatusInfosHelper.php @@ -73,6 +73,7 @@ public function showMigrationsInfo( new TableCell($v, ['colspan' => 2]), ]); } + $dataGroup = [ 'Storage' => [ 'Type' => $storage!== null ? get_class($storage) : null, @@ -120,6 +121,7 @@ public function showMigrationsInfo( $v, ]; } + if (count($nsRows) <= 0) { continue; } @@ -153,9 +155,11 @@ private function getFormattedVersionAlias(string $alias, ExecutedMigrationsSet $ return 'Already at first version'; } } + if ($alias === 'latest' && $version!== null && $executedMigrationsSet->hasMigration($version)) { return 'Already at latest version'; } + // Before first version "virtual" version number if ((string) $version === '0') { return '0'; diff --git a/lib/Doctrine/Migrations/Version/DefaultAliasResolver.php b/lib/Doctrine/Migrations/Version/DefaultAliasResolver.php index c9732a0c4c..c547225170 100644 --- a/lib/Doctrine/Migrations/Version/DefaultAliasResolver.php +++ b/lib/Doctrine/Migrations/Version/DefaultAliasResolver.php @@ -75,6 +75,7 @@ public function resolveVersionAlias(string $alias) : Version } catch (NoMigrationsFoundWithCriteria $e) { return new Version('0'); } + break; case self::ALIAS_PREV: try { @@ -82,6 +83,7 @@ public function resolveVersionAlias(string $alias) : Version } catch (NoMigrationsFoundWithCriteria $e) { return new Version('0'); } + break; case self::ALIAS_NEXT: $newMigrations = $this->migrationStatusCalculator->getNewMigrations(); @@ -91,6 +93,7 @@ public function resolveVersionAlias(string $alias) : Version } catch (NoMigrationsFoundWithCriteria $e) { throw NoMigrationsToExecute::new($e); } + break; case self::ALIAS_LATEST: try { @@ -98,6 +101,7 @@ public function resolveVersionAlias(string $alias) : Version } catch (NoMigrationsFoundWithCriteria $e) { throw NoMigrationsToExecute::new($e); } + break; default: if ($availableMigrations->hasMigration(new Version($alias))) { diff --git a/lib/Doctrine/Migrations/Version/SortedMigrationPlanCalculator.php b/lib/Doctrine/Migrations/Version/SortedMigrationPlanCalculator.php index 16155a81a8..25cf2b1394 100644 --- a/lib/Doctrine/Migrations/Version/SortedMigrationPlanCalculator.php +++ b/lib/Doctrine/Migrations/Version/SortedMigrationPlanCalculator.php @@ -61,6 +61,7 @@ public function getPlanForVersions(array $versions, string $direction) : Migrati return $migrationPlan->getVersion(); }, $planItems); $diff = array_diff($versions, $plannedVersions); + throw MigrationClassNotFound::new((string) reset($diff)); } diff --git a/tests/Doctrine/Migrations/Tests/Configuration/Configuration/JsonLoaderTest.php b/tests/Doctrine/Migrations/Tests/Configuration/Configuration/JsonLoaderTest.php index 91b1e0489d..3fed01c599 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/Configuration/JsonLoaderTest.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/Configuration/JsonLoaderTest.php @@ -11,7 +11,7 @@ class JsonLoaderTest extends LoaderTest { public function load(string $prefix = '') : Configuration { - $loader = new JsonFile(__DIR__ . '/../_files/config' . ($prefix!==''? ('_' . $prefix) : '') . '.json'); + $loader = new JsonFile(__DIR__ . '/../_files/config' . ($prefix!==''? '_' . $prefix : '') . '.json'); return $loader->getConfiguration(); } diff --git a/tests/Doctrine/Migrations/Tests/Configuration/Configuration/LoaderTest.php b/tests/Doctrine/Migrations/Tests/Configuration/Configuration/LoaderTest.php index e9bf96b91d..06ec9b713a 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/Configuration/LoaderTest.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/Configuration/LoaderTest.php @@ -10,8 +10,8 @@ use Doctrine\Migrations\Metadata\Storage\TableMetadataStorageConfiguration; use InvalidArgumentException; use PHPUnit\Framework\TestCase; -use const DIRECTORY_SEPARATOR; use function dirname; +use const DIRECTORY_SEPARATOR; abstract class LoaderTest extends TestCase { diff --git a/tests/Doctrine/Migrations/Tests/Configuration/Configuration/PhpLoaderTest.php b/tests/Doctrine/Migrations/Tests/Configuration/Configuration/PhpLoaderTest.php index 9a00286dac..7afd1fc618 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/Configuration/PhpLoaderTest.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/Configuration/PhpLoaderTest.php @@ -11,7 +11,7 @@ class PhpLoaderTest extends LoaderTest { public function load(string $prefix = '') : Configuration { - $loader = new PhpFile(__DIR__ . '/../_files/config' . ($prefix!==''? ('_' . $prefix) : '') . '.php'); + $loader = new PhpFile(__DIR__ . '/../_files/config' . ($prefix!==''? '_' . $prefix : '') . '.php'); return $loader->getConfiguration(); } diff --git a/tests/Doctrine/Migrations/Tests/Configuration/Configuration/XmlLoaderTest.php b/tests/Doctrine/Migrations/Tests/Configuration/Configuration/XmlLoaderTest.php index e0dfbd1b90..2aaab94c7b 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/Configuration/XmlLoaderTest.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/Configuration/XmlLoaderTest.php @@ -11,7 +11,7 @@ class XmlLoaderTest extends LoaderTest { public function load(string $prefix = '') : Configuration { - $loader = new XmlFile(__DIR__ . '/../_files/config' . ($prefix!==''? ('_' . $prefix) : '') . '.xml'); + $loader = new XmlFile(__DIR__ . '/../_files/config' . ($prefix!==''? '_' . $prefix : '') . '.xml'); return $loader->getConfiguration(); } diff --git a/tests/Doctrine/Migrations/Tests/Configuration/Configuration/YamlLoaderTest.php b/tests/Doctrine/Migrations/Tests/Configuration/Configuration/YamlLoaderTest.php index 6ba6f8746b..54efe2a6e4 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/Configuration/YamlLoaderTest.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/Configuration/YamlLoaderTest.php @@ -11,7 +11,7 @@ class YamlLoaderTest extends LoaderTest { public function load(string $prefix = '') : Configuration { - $loader = new YamlFile(__DIR__ . '/../_files/config' . ($prefix!==''? ('_' . $prefix) : '') . '.yml'); + $loader = new YamlFile(__DIR__ . '/../_files/config' . ($prefix!==''? '_' . $prefix : '') . '.yml'); return $loader->getConfiguration(); } diff --git a/tests/Doctrine/Migrations/Tests/Finder/RecursiveRegexFinderTest.php b/tests/Doctrine/Migrations/Tests/Finder/RecursiveRegexFinderTest.php index 4918712055..9bcc2240cc 100644 --- a/tests/Doctrine/Migrations/Tests/Finder/RecursiveRegexFinderTest.php +++ b/tests/Doctrine/Migrations/Tests/Finder/RecursiveRegexFinderTest.php @@ -6,11 +6,11 @@ use Doctrine\Migrations\Finder\RecursiveRegexFinder; use InvalidArgumentException; -use const PHP_OS; use function count; use function in_array; use function sort; use function stripos; +use const PHP_OS; class RecursiveRegexFinderTest extends FinderTestCase { diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationDirectoryHelperTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationDirectoryHelperTest.php index 321fc64279..19fccce39b 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationDirectoryHelperTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationDirectoryHelperTest.php @@ -9,12 +9,12 @@ use Doctrine\Migrations\Tests\MigrationTestCase; use Doctrine\Migrations\Tools\Console\Helper\MigrationDirectoryHelper; use InvalidArgumentException; -use const DIRECTORY_SEPARATOR; use function date; use function mkdir; use function sys_get_temp_dir; use function tempnam; use function unlink; +use const DIRECTORY_SEPARATOR; class MigrationDirectoryHelperTest extends MigrationTestCase { diff --git a/tests/Doctrine/Migrations/Tests/Version/AliasResolverTest.php b/tests/Doctrine/Migrations/Tests/Version/AliasResolverTest.php index a842551407..d0e708b7eb 100644 --- a/tests/Doctrine/Migrations/Tests/Version/AliasResolverTest.php +++ b/tests/Doctrine/Migrations/Tests/Version/AliasResolverTest.php @@ -46,6 +46,7 @@ public function testAliases(string $alias, ?string $expectedVersion, ?string $ex if ($expectedException !== null) { $this->expectException($expectedException); } + $migrationClass = $this->createMock(AbstractMigration::class); foreach (['A', 'B', 'C'] as $version) { $this->migrationRepository->registerMigrationInstance(new Version($version), $migrationClass); @@ -77,6 +78,7 @@ public function testAliasesWithNoExecuted(string $alias, ?string $expectedVersio foreach (['A', 'B', 'C'] as $version) { $this->migrationRepository->registerMigrationInstance(new Version($version), $migrationClass); } + $resolvedAlias = $this->versionAliasResolver->resolveVersionAlias($alias); if ($expectedVersion === null) { return; diff --git a/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php b/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php index 89a71a273e..cc82827bba 100644 --- a/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php +++ b/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php @@ -329,6 +329,7 @@ public function onMigrationsVersionSkipped() : void self::assertFalse($this->migration->preDownExecuted); self::assertFalse($this->migration->postDownExecuted); } + self::assertFalse($migrationSucceed); } @@ -401,6 +402,7 @@ public function onMigrationsVersionSkipped() : void self::assertFalse($this->migration->preDownExecuted); self::assertFalse($this->migration->postDownExecuted); } + self::assertFalse($migrationSucceed); }