diff --git a/composer.json b/composer.json index e6223719ec..182e0875f5 100644 --- a/composer.json +++ b/composer.json @@ -24,10 +24,11 @@ "doctrine/orm": "^2.6", "jdorn/sql-formatter": "^1.1", "mikey179/vfsStream": "^1.6", - "phpstan/phpstan": "^0.10", - "phpstan/phpstan-deprecation-rules": "^0.10", - "phpstan/phpstan-phpunit": "^0.10", - "phpstan/phpstan-strict-rules": "^0.10", + "phpstan/phpstan": "^0.11", + "phpstan/phpstan-deprecation-rules": "^0.11", + "phpstan/phpstan-phpunit": "^0.11", + "phpstan/phpstan-strict-rules": "^0.11", + "phpstan/phpstan-symfony": "^0.11.6", "phpunit/phpunit": "^7.0", "symfony/process": "^3.4||^4.0", "symfony/yaml": "^3.4||^4.0" diff --git a/lib/Doctrine/Migrations/Configuration/Loader/ArrayLoader.php b/lib/Doctrine/Migrations/Configuration/Loader/ArrayLoader.php index 97615761e3..97d19fa8ad 100644 --- a/lib/Doctrine/Migrations/Configuration/Loader/ArrayLoader.php +++ b/lib/Doctrine/Migrations/Configuration/Loader/ArrayLoader.php @@ -78,12 +78,17 @@ private static function applyConfigs(array $configMap, $object, array $data) : v if (is_array($configMap[$configurationKey])) { if ($configurationKey === 'table_storage') { $storageConfig = new TableMetadataStorageConfiguration(); + assert($object instanceof Configuration); $object->setMetadataStorageConfiguration($storageConfig); self::applyConfigs($configMap[$configurationKey], $storageConfig, $configurationValue); } } else { + $callable = $configMap[$configurationKey] instanceof Closure + ? $configMap[$configurationKey] + : [$object, $configMap[$configurationKey]]; + assert(is_callable($callable)); call_user_func( - $configMap[$configurationKey] instanceof Closure ? $configMap[$configurationKey] : [$object, $configMap[$configurationKey]], + $callable, $configurationValue, $object, $data diff --git a/lib/Doctrine/Migrations/Configuration/Loader/XmlFileLoader.php b/lib/Doctrine/Migrations/Configuration/Loader/XmlFileLoader.php index ccdf806e1f..ea75180582 100644 --- a/lib/Doctrine/Migrations/Configuration/Loader/XmlFileLoader.php +++ b/lib/Doctrine/Migrations/Configuration/Loader/XmlFileLoader.php @@ -27,29 +27,32 @@ class XmlFileLoader extends AbstractFileLoader /** * @return mixed[] */ - private function extractParameters(SimpleXMLElement $root, bool $nodes = true) : array + private function extractParameters(SimpleXMLElement $root, bool $loopOverNodes = true): array { $config = []; - foreach ($nodes ? $root->children() : $root->attributes() as $node) { + + $itemsToCheck = $loopOverNodes ? $root->children() : $root->attributes(); + + if (!($itemsToCheck instanceof SimpleXMLElement)){ + return $config; + } + foreach ($itemsToCheck as $node) { $nodeName = strtr($node->getName(), '-', '_'); if ($nodeName === 'migrations_paths') { $config['migrations_paths'] = []; foreach ($node->{'path'} as $pathNode) { - $config['migrations_paths'][(string) $pathNode['namespace']] = (string) $pathNode; + $config['migrations_paths'][(string)$pathNode['namespace']] = (string)$pathNode; } } elseif ($nodeName === 'storage' && $node->{'table-storage'} instanceof SimpleXMLElement) { $config['table_storage'] = $this->extractParameters($node->{'table-storage'}, false); } else { - $config[$nodeName] = (string) $node; + $config[$nodeName] = (string)$node; } } return $config; } - /** - * @param mixed $file - */ public function __construct(?ArrayLoader $arrayLoader = null) { $this->arrayLoader = $arrayLoader ?: new ArrayLoader(); @@ -58,32 +61,34 @@ public function __construct(?ArrayLoader $arrayLoader = null) /** * @param mixed|string $file */ - public function load($file) : Configuration + public function load($file): Configuration { - if (! file_exists($file)) { + if (!file_exists($file)) { throw FileNotFound::new(); } - libxml_use_internal_errors(true); + try { + libxml_use_internal_errors(true); - $xml = new DOMDocument(); + $xml = new DOMDocument(); - if ($xml->load($file) === false) { - throw XmlNotValid::malformed(); - } + if ($xml->load($file) === false) { + throw XmlNotValid::malformed(); + } - $xsdPath = __DIR__ . DIRECTORY_SEPARATOR . 'XML' . DIRECTORY_SEPARATOR . 'configuration.xsd'; -// @todo restore validation -// if (! $xml->schemaValidate($xsdPath)) { -// libxml_clear_errors(); -// -// throw XmlNotValid::failedValidation(); -// } + $xsdPath = __DIR__ . DIRECTORY_SEPARATOR . 'XML' . DIRECTORY_SEPARATOR . 'configuration.xsd'; + if ($xml->schemaValidate($xsdPath) === false) { + throw XmlNotValid::failedValidation(); + } + } finally { + libxml_clear_errors(); + libxml_use_internal_errors(false); + } $rawXML = file_get_contents($file); assert($rawXML !== false); $root = simplexml_load_string($rawXML, SimpleXMLElement::class, LIBXML_NOCDATA); - assert($xml !== false); + assert($root !== false); $config = $this->extractParameters($root); diff --git a/lib/Doctrine/Migrations/Finder/GlobFinder.php b/lib/Doctrine/Migrations/Finder/GlobFinder.php index aa4045e045..ae0fb39ae1 100644 --- a/lib/Doctrine/Migrations/Finder/GlobFinder.php +++ b/lib/Doctrine/Migrations/Finder/GlobFinder.php @@ -13,13 +13,13 @@ final class GlobFinder extends Finder { /** - * @return string[] + * {@inheritDoc} */ public function findMigrations(string $directory, ?string $namespace = null) : array { $dir = $this->getRealPath($directory); - $files = glob(rtrim($dir, '/') . '/Version*.php'); + $files = glob(rtrim($dir, '/') . '/Version*.php') ?: []; return $this->loadMigrations($files, $namespace); } diff --git a/lib/Doctrine/Migrations/Generator/FileBuilder.php b/lib/Doctrine/Migrations/Generator/FileBuilder.php index 3867e4acc2..e70112b0bd 100644 --- a/lib/Doctrine/Migrations/Generator/FileBuilder.php +++ b/lib/Doctrine/Migrations/Generator/FileBuilder.php @@ -6,7 +6,6 @@ use DateTimeImmutable; use DateTimeInterface; -use Doctrine\DBAL\Platforms\AbstractPlatform; use function sprintf; /** @@ -16,9 +15,6 @@ */ final class FileBuilder implements FileBuilderInterface { - /** @var AbstractPlatform */ - private $platform; - /** @param string[][] $queriesByVersion */ public function buildMigrationFile( array $queriesByVersion, diff --git a/lib/Doctrine/Migrations/Metadata/AvailableMigrationsList.php b/lib/Doctrine/Migrations/Metadata/AvailableMigrationsList.php index 859019d925..fd9d50deb1 100644 --- a/lib/Doctrine/Migrations/Metadata/AvailableMigrationsList.php +++ b/lib/Doctrine/Migrations/Metadata/AvailableMigrationsList.php @@ -45,16 +45,13 @@ public function getLast(int $offset = 0) : AvailableMigration { $offset = count($this->items)-1-(-1*$offset); if (! isset($this->items[$offset])) { - throw NoMigrationsFoundWithCriteria::new('first' . ($offset>0 ? ('+' . $offset) : '')); + throw NoMigrationsFoundWithCriteria::new('last' . ($offset>0 ? ('+' . $offset) : '')); } return $this->items[$offset]; } - /** - * @return int - */ - public function count() + public function count() : int { return count($this->items); } diff --git a/lib/Doctrine/Migrations/Metadata/ExecutedMigrationsSet.php b/lib/Doctrine/Migrations/Metadata/ExecutedMigrationsSet.php index f0e2e47d48..ac1b1eb306 100644 --- a/lib/Doctrine/Migrations/Metadata/ExecutedMigrationsSet.php +++ b/lib/Doctrine/Migrations/Metadata/ExecutedMigrationsSet.php @@ -51,10 +51,7 @@ public function getLast(int $offset = 0) : ExecutedMigration return $this->items[$offset]; } - /** - * @return int - */ - public function count() + public function count() : int { return count($this->items); } diff --git a/lib/Doctrine/Migrations/Metadata/MigrationPlanList.php b/lib/Doctrine/Migrations/Metadata/MigrationPlanList.php index 2ce5612d3d..941b960ad8 100644 --- a/lib/Doctrine/Migrations/Metadata/MigrationPlanList.php +++ b/lib/Doctrine/Migrations/Metadata/MigrationPlanList.php @@ -27,10 +27,7 @@ public function __construct(array $items, string $direction) $this->direction = $direction; } - /** - * @return int - */ - public function count() + public function count() : int { return count($this->items); } diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php index 26a4134f41..d996adafa7 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php @@ -42,13 +42,13 @@ protected function configure() : void ->addOption( 'editor-cmd', null, - InputOption::VALUE_OPTIONAL, + InputOption::VALUE_REQUIRED, 'Open file with this command upon creation.' ) ->addOption( 'filter-expression', null, - InputOption::VALUE_OPTIONAL, + InputOption::VALUE_REQUIRED, 'Tables which are filtered by Regular Expression.' ) ->addOption( @@ -60,7 +60,7 @@ protected function configure() : void ->addOption( 'line-length', null, - InputOption::VALUE_OPTIONAL, + InputOption::VALUE_REQUIRED, 'Max line length of unformatted lines.', 120 ) @@ -69,7 +69,7 @@ protected function configure() : void null, InputOption::VALUE_OPTIONAL, 'Check Database Platform to the generated code.', - true + 1 ); } @@ -80,10 +80,10 @@ public function execute( InputInterface $input, OutputInterface $output ) : ?int { - $filterExpression = $input->getOption('filter-expression') ?? null; - $formatted = (bool) $input->getOption('formatted'); - $lineLength = (int) $input->getOption('line-length'); + $filterExpression = (string)$input->getOption('filter-expression') ?: null; + $lineLength = (int)$input->getOption('line-length'); $checkDbPlatform = filter_var($input->getOption('check-database-platform'), FILTER_VALIDATE_BOOLEAN); + $formatted = filter_var($input->getOption('formatted'), FILTER_VALIDATE_BOOLEAN); if ($formatted) { if (! class_exists('SqlFormatter')) { @@ -107,6 +107,7 @@ public function execute( $editorCommand = $input->getOption('editor-cmd'); if ($editorCommand !== null) { + assert(is_string($editorCommand)); $this->procOpen($editorCommand, $path); } diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/DumpSchemaCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/DumpSchemaCommand.php index 9bc23a8802..9254c19d1c 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/DumpSchemaCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/DumpSchemaCommand.php @@ -74,7 +74,7 @@ public function execute( InputInterface $input, OutputInterface $output ) : ?int { - $formatted = (bool) $input->getOption('formatted'); + $formatted = $input->getOption('formatted'); $lineLength = (int) $input->getOption('line-length'); $schemaDumper = $this->getDependencyFactory()->getSchemaDumper(); @@ -100,6 +100,7 @@ public function execute( $dirs = $configuration->getMigrationDirectories(); $namespace = key($dirs); } + assert(is_string($namespace)); $path = $schemaDumper->dump( $versionNumber, @@ -111,6 +112,7 @@ public function execute( $editorCommand = $input->getOption('editor-cmd'); if ($editorCommand !== null) { + assert(is_string($editorCommand)); $this->procOpen($editorCommand, $path); } diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/ExecuteCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/ExecuteCommand.php index a190b5f6ab..949402a5d6 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/ExecuteCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/ExecuteCommand.php @@ -111,6 +111,12 @@ public function execute(InputInterface $input, OutputInterface $output) : ?int $path = is_string($path) ? $path : getcwd(); + if (!is_string($path) || !is_dir($path) || !is_writable($path)) { + $output->writeln('Directory not writeable!'); + + return 1; + } + $writer = $this->getDependencyFactory()->getQueryWriter(); $writer->write($path, $direction, $sql); diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/GenerateCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/GenerateCommand.php index 035314e893..90ca1ba727 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/GenerateCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/GenerateCommand.php @@ -65,13 +65,14 @@ 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 = $namespace . '\\Version' . $versionNumber; $path = $migrationGenerator->generateMigration($versionNumber, $namespace); $editorCommand = $input->getOption('editor-cmd'); if ($editorCommand !== null) { + assert(is_string($editorCommand)); $this->procOpen($editorCommand, $path); } diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php index 161657e09c..c30521312a 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php @@ -117,7 +117,7 @@ public function execute(InputInterface $input, OutputInterface $output) : ?int { $this->outputHeader($output); - $versionAlias = (string) $input->getArgument('version'); + $versionAlias = $input->getArgument('version'); $path = $input->getOption('write-sql'); try { @@ -152,6 +152,11 @@ public function execute(InputInterface $input, OutputInterface $output) : ?int $sql = $migrator->migrate($plan, $migratorConfiguration); $path = is_string($path) ? $path : getcwd(); + if (!is_string($path) || !is_dir($path) || !is_writable($path)) { + $output->writeln('Directory not writeable!'); + + return 1; + } $writer = $this->getDependencyFactory()->getQueryWriter(); $writer->write($path, $plan->getDirection(), $sql); @@ -185,7 +190,9 @@ private function checkExecutedUnavailableMigrations( foreach ($executedUnavailableMigrations->getItems() as $executedUnavailableMigration) { $output->writeln(sprintf( ' >> %s (%s)', - $executedUnavailableMigration->getExecutedAt() ? $executedUnavailableMigration->getExecutedAt()->format('Y-m-d H:i:s') : null, + $executedUnavailableMigration->getExecutedAt() !== null + ? $executedUnavailableMigration->getExecutedAt()->format('Y-m-d H:i:s') + : null, $executedUnavailableMigration->getVersion() )); } diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/StatusCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/StatusCommand.php index 49b2c94568..e2481b6ae2 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/StatusCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/StatusCommand.php @@ -91,7 +91,7 @@ private function showUnavailableVersions(OutputInterface $output, ExecutedMigrat foreach ($executedUnavailableMigrations->getItems() as $executedUnavailableMigration) { $table->addRow([ (string) $executedUnavailableMigration->getVersion(), - $executedUnavailableMigration->getExecutedAt() + $executedUnavailableMigration->getExecutedAt() !== null ? $executedUnavailableMigration->getExecutedAt()->format('Y-m-d H:i:s') : null, ]); @@ -99,9 +99,6 @@ private function showUnavailableVersions(OutputInterface $output, ExecutedMigrat $table->render(); } - /** - * @param AvailableMigration[] $versions - */ private function showVersions( AvailableMigrationsList $availableMigrationsSet, ExecutedMigrationsSet $executedMigrationsSet, diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/VersionCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/VersionCommand.php index 88307fc612..151666d8ed 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/VersionCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/VersionCommand.php @@ -91,7 +91,7 @@ public function execute(InputInterface $input, OutputInterface $output) : ?int throw InvalidOptionUsage::new('You must specify whether you want to --add or --delete the specified version.'); } - $this->markMigrated = (bool) $input->getOption('add'); + $this->markMigrated = $input->getOption('add'); if ($input->isInteractive()) { $question = 'WARNING! You are about to add, delete or synchronize migration versions from the version table that could result in data lost. Are you sure you wish to continue? (y/n)'; @@ -122,7 +122,7 @@ private function markVersions(InputInterface $input, OutputInterface $output) : if ($allOption === true) { $availableVersions = $this->getDependencyFactory()->getMigrationRepository()->getMigrations(); - if ((bool) $input->getOption('delete') === true) { + if ($input->getOption('delete') === true) { foreach ($executedMigrations->getItems() as $availableMigration) { $this->mark($input, $output, $availableMigration->getVersion(), false, $executedMigrations); } @@ -130,8 +130,10 @@ private function markVersions(InputInterface $input, OutputInterface $output) : foreach ($availableVersions->getItems() as $availableMigration) { $this->mark($input, $output, $availableMigration->getVersion(), true, $executedMigrations); } - } else { + } elseif ($affectedVersion !== null) { $this->mark($input, $output, new Version($affectedVersion), false, $executedMigrations); + } else { + throw InvalidOptionUsage::new('You must specify the version or use the --all argument.'); } } @@ -150,7 +152,7 @@ private function mark(InputInterface $input, OutputInterface $output, Version $v $storage = $this->getDependencyFactory()->getMetadataStorage(); if ($availableMigration === null) { - if ((bool) $input->getOption('delete') === false) { + if ($input->getOption('delete') === false) { throw UnknownMigrationVersion::new((string) $version); } diff --git a/lib/Doctrine/Migrations/Tools/Console/Helper/ConfigurationHelper.php b/lib/Doctrine/Migrations/Tools/Console/Helper/ConfigurationHelper.php index b5645ab254..5c93429552 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Helper/ConfigurationHelper.php +++ b/lib/Doctrine/Migrations/Tools/Console/Helper/ConfigurationHelper.php @@ -70,10 +70,10 @@ private function configExists(string $config) : bool */ private function loadConfig(string $configFile) : Configuration { - $info = pathinfo($configFile); + $extension = pathinfo($configFile, PATHINFO_EXTENSION); try { - return $this->loader->getLoader($info['extension'])->load($configFile); + return $this->loader->getLoader($extension)->load($configFile); } catch (UnknownLoader $e) { throw FileTypeNotSupported::new(); } diff --git a/lib/Doctrine/Migrations/Version/AliasResolver.php b/lib/Doctrine/Migrations/Version/AliasResolver.php index e1e6410701..93dd2a1290 100644 --- a/lib/Doctrine/Migrations/Version/AliasResolver.php +++ b/lib/Doctrine/Migrations/Version/AliasResolver.php @@ -73,14 +73,14 @@ public function resolveVersionAlias(string $alias) : Version } catch (NoMigrationsFoundWithCriteria $e) { return new Version('0'); } - + break; case self::ALIAS_PREV: try { return $executedMigrations->getLast(-1)->getVersion(); } catch (NoMigrationsFoundWithCriteria $e) { return new Version('0'); } - + break; case self::ALIAS_NEXT: $newMigrations = $this->migrationPlanCalculator->getNewMigrations(); @@ -89,13 +89,14 @@ public function resolveVersionAlias(string $alias) : Version } catch (NoMigrationsFoundWithCriteria $e) { throw NoMigrationsToExecute::new(); } - + break; case self::ALIAS_LATEST: try { return $availableMigrations->getLast()->getVersion(); } catch (NoMigrationsFoundWithCriteria $e) { throw NoMigrationsToExecute::new(); } + break; default: if ($availableMigrations->hasMigration(new Version($alias))) { return $availableMigrations->getMigration(new Version($alias))->getVersion(); diff --git a/lib/Doctrine/Migrations/Version/Executor.php b/lib/Doctrine/Migrations/Version/Executor.php index 06cf44caa5..c3174acd8d 100644 --- a/lib/Doctrine/Migrations/Version/Executor.php +++ b/lib/Doctrine/Migrations/Version/Executor.php @@ -42,7 +42,7 @@ final class Executor implements ExecutorInterface /** @var Stopwatch */ private $stopwatch; - /** @var string[] */ + /** @var array */ private $sql = []; /** @var mixed[] */ diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 081f57d439..c7fdebbea0 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -6,6 +6,8 @@ parameters: autoload_directories: - %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Finder/_features - %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Finder/_files + excludes_analyse: + - %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTestSource/Migrations/Version123.php autoload_files: - %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/realpath.php ignoreErrors: @@ -13,9 +15,13 @@ parameters: - '~ProxyManager\\Proxy\\VirtualProxyInterface~' - '~^Parameter #1 \$files of method Doctrine\\Migrations\\Finder\\Finder::loadMigrationClasses\(\) expects array, array given\.\z~' - '~^Class Doctrine\\Migrations\\Tests\\DoesNotExistAtAll not found\.\z~' - + - '~Variable method call on Doctrine\\Migrations\\AbstractMigration~' + - '~^Variable property access on mixed\.$~' + symfony: + console_application_loader: %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/doctrine-migrations-phpstan-app.php includes: - vendor/phpstan/phpstan-deprecation-rules/rules.neon - vendor/phpstan/phpstan-phpunit/extension.neon - vendor/phpstan/phpstan-phpunit/rules.neon - vendor/phpstan/phpstan-strict-rules/rules.neon + - vendor/phpstan/phpstan-symfony/extension.neon diff --git a/tests/Doctrine/Migrations/Tests/AbstractMigrationTest.php b/tests/Doctrine/Migrations/Tests/AbstractMigrationTest.php index 19b344473c..05225e390a 100644 --- a/tests/Doctrine/Migrations/Tests/AbstractMigrationTest.php +++ b/tests/Doctrine/Migrations/Tests/AbstractMigrationTest.php @@ -15,7 +15,7 @@ class AbstractMigrationTest extends MigrationTestCase /** @var AbstractMigrationStub */ private $migration; - /** @var LoggerInterface */ + /** @var TestLogger */ private $logger; protected function setUp() : void diff --git a/tests/Doctrine/Migrations/Tests/Generator/SqlGeneratorTest.php b/tests/Doctrine/Migrations/Tests/Generator/SqlGeneratorTest.php index d50e415ad8..f9c8250b70 100644 --- a/tests/Doctrine/Migrations/Tests/Generator/SqlGeneratorTest.php +++ b/tests/Doctrine/Migrations/Tests/Generator/SqlGeneratorTest.php @@ -27,9 +27,7 @@ final class SqlGeneratorTest extends TestCase /** @var string[] */ private $sql; - /** - * @var MockObject|TableMetadataStorageConfiguration - */ + /** @var MockObject|TableMetadataStorageConfiguration */ private $metadataConfig; public function testGenerate() : void diff --git a/tests/Doctrine/Migrations/Tests/Helper.php b/tests/Doctrine/Migrations/Tests/Helper.php index fde13c7678..186f5367a4 100644 --- a/tests/Doctrine/Migrations/Tests/Helper.php +++ b/tests/Doctrine/Migrations/Tests/Helper.php @@ -33,7 +33,7 @@ public static function deleteDir(string $path) : bool $files = glob($path . '/*'); - if ($files !== []) { + if ($files !== [] && $files !== false) { array_map($classFunction, $files); @rmdir($path); diff --git a/tests/Doctrine/Migrations/Tests/Metadata/Storage/TableMetadataStorageConfigurationTest.php b/tests/Doctrine/Migrations/Tests/Metadata/Storage/TableMetadataStorageConfigurationTest.php index 0ee3831790..93863aa846 100644 --- a/tests/Doctrine/Migrations/Tests/Metadata/Storage/TableMetadataStorageConfigurationTest.php +++ b/tests/Doctrine/Migrations/Tests/Metadata/Storage/TableMetadataStorageConfigurationTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Doctrine\Migrations\Tests\Metadata\Storage\Configuration\Storage; +namespace Doctrine\Migrations\Tests\Metadata\Storage\Storage; use Doctrine\Migrations\Metadata\Storage\TableMetadataStorageConfiguration; use PHPUnit\Framework\TestCase; diff --git a/tests/Doctrine/Migrations/Tests/MigrationTestCase.php b/tests/Doctrine/Migrations/Tests/MigrationTestCase.php index b75822d386..fb7ee328bd 100644 --- a/tests/Doctrine/Migrations/Tests/MigrationTestCase.php +++ b/tests/Doctrine/Migrations/Tests/MigrationTestCase.php @@ -7,7 +7,6 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; use PHPUnit\Framework\TestCase; -use Psr\Log\LoggerInterface; use function implode; abstract class MigrationTestCase extends TestCase diff --git a/tests/Doctrine/Migrations/Tests/Stub/AbstractMigrationStub.php b/tests/Doctrine/Migrations/Tests/Stub/AbstractMigrationStub.php index 9722f61429..ae78f4f109 100644 --- a/tests/Doctrine/Migrations/Tests/Stub/AbstractMigrationStub.php +++ b/tests/Doctrine/Migrations/Tests/Stub/AbstractMigrationStub.php @@ -6,7 +6,6 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; -use Doctrine\Migrations\Version\Version; class AbstractMigrationStub extends AbstractMigration { diff --git a/tests/Doctrine/Migrations/Tests/TestLogger.php b/tests/Doctrine/Migrations/Tests/TestLogger.php index 8c6091fa5f..94988c6a98 100644 --- a/tests/Doctrine/Migrations/Tests/TestLogger.php +++ b/tests/Doctrine/Migrations/Tests/TestLogger.php @@ -21,8 +21,8 @@ class TestLogger extends AbstractLogger public $logs = []; /** - * @param string $level - * @param string $message + * @param mixed $level + * @param string $message * @param mixed[] $context */ public function log($level, $message, array $context = []) : void diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/StatusCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/StatusCommandTest.php index 7095dcc2b1..51811a4f7e 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/StatusCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/StatusCommandTest.php @@ -13,7 +13,6 @@ use Doctrine\Migrations\MigrationRepository; use Doctrine\Migrations\Tests\MigrationTestCase; use Doctrine\Migrations\Tools\Console\Command\StatusCommand; -use Doctrine\Migrations\Tools\Console\Command\VersionCommand; use Doctrine\Migrations\Version\Direction; use Doctrine\Migrations\Version\ExecutionResult; use Doctrine\Migrations\Version\Version; diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/UpToDateCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/UpToDateCommandTest.php index 318fc46627..fbaf60f40a 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/UpToDateCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/UpToDateCommandTest.php @@ -16,7 +16,6 @@ use Doctrine\Migrations\Version\Direction; use Doctrine\Migrations\Version\ExecutionResult; use Doctrine\Migrations\Version\Version; -use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Tester\CommandTester; use function sys_get_temp_dir; diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationDirectoryHelperTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationDirectoryHelperTest.php index 521b766917..ff425569a0 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationDirectoryHelperTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationDirectoryHelperTest.php @@ -5,6 +5,7 @@ namespace Doctrine\Migrations\Tests\Tools\Console\Helper; use Doctrine\Migrations\Configuration\Configuration; +use Doctrine\Migrations\Tests\Helper; use Doctrine\Migrations\Tests\MigrationTestCase; use Doctrine\Migrations\Tools\Console\Helper\MigrationDirectoryHelper; use InvalidArgumentException; @@ -43,7 +44,7 @@ public function setUp() : void public function tearDown() : void { - rrmdir($this->tempDir); + Helper::deleteDir($this->tempDir); } public function testMigrationDirectoryHelperReturnConfiguredDir() : void @@ -89,22 +90,3 @@ public function testMigrationsDirectoryHelperWithFolderThatDoesNotExists() : voi } } } - -function rrmdir(string $src) : void -{ - $dir = opendir($src); - while (( $file = readdir($dir)) !== false) { - if (( $file === '.' ) || ( $file === '..' )) { - continue; - } - - $full = $src . '/' . $file; - if (is_dir($full)) { - rrmdir($full); - } else { - unlink($full); - } - } - closedir($dir); - rmdir($src); -} diff --git a/tests/Doctrine/Migrations/Tests/doctrine-migrations-phpstan-app.php b/tests/Doctrine/Migrations/Tests/doctrine-migrations-phpstan-app.php new file mode 100644 index 0000000000..a779732c09 --- /dev/null +++ b/tests/Doctrine/Migrations/Tests/doctrine-migrations-phpstan-app.php @@ -0,0 +1,18 @@ +set(new QuestionHelper(), 'question'); + +return ConsoleRunner::createApplication($helperSet, [new DiffCommand()]);