From f9b4c8032276460afd9dfa62fb215734b4380d90 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Fri, 1 Apr 2022 08:38:22 +0200 Subject: [PATCH] PHPStan 1.5, Doctrine Coding Standard 9 (#1248) --- composer.json | 12 ++++++------ .../Tools/Console/Command/CurrentCommand.php | 2 +- .../Migrations/Tools/Console/Command/DiffCommand.php | 2 +- .../Tools/Console/Command/DumpSchemaCommand.php | 2 +- .../Tools/Console/Command/ExecuteCommand.php | 2 +- .../Tools/Console/Command/GenerateCommand.php | 2 +- .../Tools/Console/Command/LatestCommand.php | 2 +- .../Migrations/Tools/Console/Command/ListCommand.php | 2 +- .../Tools/Console/Command/MigrateCommand.php | 2 +- .../Tools/Console/Command/RollupCommand.php | 2 +- .../Tools/Console/Command/StatusCommand.php | 2 +- .../Tools/Console/Command/SyncMetadataCommand.php | 2 +- .../Tools/Console/Command/UpToDateCommand.php | 2 +- .../Tools/Console/Command/VersionCommand.php | 2 +- phpstan-common.neon.dist | 7 +++++++ phpstan-dbal-2.neon.dist | 5 +++++ .../Tests/Event/Listeners/AutoCommitListenerTest.php | 2 +- .../Tests/Tools/Console/Command/DiffCommandTest.php | 4 ++-- .../Tools/Console/Command/MigrateCommandTest.php | 3 ++- 19 files changed, 36 insertions(+), 23 deletions(-) diff --git a/composer.json b/composer.json index 28fa42c55f..80023f2412 100644 --- a/composer.json +++ b/composer.json @@ -36,16 +36,16 @@ }, "require-dev": { "ext-pdo_sqlite": "*", - "doctrine/coding-standard": "^8.0", + "doctrine/coding-standard": "^9", "doctrine/orm": "^2.6", "doctrine/persistence": "^1.3 || ^2.0", "doctrine/sql-formatter": "^1.0", "ergebnis/composer-normalize": "^2.9", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-deprecation-rules": "^0.12", - "phpstan/phpstan-phpunit": "^0.12", - "phpstan/phpstan-strict-rules": "^0.12", - "phpstan/phpstan-symfony": "^0.12", + "phpstan/phpstan": "^1.5", + "phpstan/phpstan-deprecation-rules": "^1", + "phpstan/phpstan-phpunit": "^1.1", + "phpstan/phpstan-strict-rules": "^1.1", + "phpstan/phpstan-symfony": "^1.1", "phpunit/phpunit": "^8.5 || ^9.4", "symfony/cache": "^3.4.26 || ^4.2.12 || ^5.0 || ^6.0", "symfony/process": "^3.4 || ^4.0 || ^5.0 || ^6.0", diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/CurrentCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/CurrentCommand.php index 5381e2fde8..52184a1cd1 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/CurrentCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/CurrentCommand.php @@ -15,7 +15,7 @@ */ final class CurrentCommand extends DoctrineCommand { - /** @var string */ + /** @var string|null */ protected static $defaultName = 'migrations:current'; protected function configure(): void diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php index 88afa84f4f..cbf490384f 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php @@ -31,7 +31,7 @@ */ final class DiffCommand extends DoctrineCommand { - /** @var string */ + /** @var string|null */ protected static $defaultName = 'migrations:diff'; protected function configure(): void diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/DumpSchemaCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/DumpSchemaCommand.php index ac331e2bf9..23c8480df4 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/DumpSchemaCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/DumpSchemaCommand.php @@ -27,7 +27,7 @@ */ final class DumpSchemaCommand extends DoctrineCommand { - /** @var string */ + /** @var string|null */ protected static $defaultName = 'migrations:dump-schema'; protected function configure(): void diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/ExecuteCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/ExecuteCommand.php index c5c802212e..0b4b61cf12 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/ExecuteCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/ExecuteCommand.php @@ -25,7 +25,7 @@ */ final class ExecuteCommand extends DoctrineCommand { - /** @var string */ + /** @var string|null */ protected static $defaultName = 'migrations:execute'; protected function configure(): void diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/GenerateCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/GenerateCommand.php index 7a348c1762..c7f06a79e4 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/GenerateCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/GenerateCommand.php @@ -19,7 +19,7 @@ */ final class GenerateCommand extends DoctrineCommand { - /** @var string */ + /** @var string|null */ protected static $defaultName = 'migrations:generate'; protected function configure(): void diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/LatestCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/LatestCommand.php index d109ce7514..cadc50a329 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/LatestCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/LatestCommand.php @@ -15,7 +15,7 @@ */ final class LatestCommand extends DoctrineCommand { - /** @var string */ + /** @var string|null */ protected static $defaultName = 'migrations:latest'; protected function configure(): void diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/ListCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/ListCommand.php index 1877da6d8a..7d7317e3ac 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/ListCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/ListCommand.php @@ -22,7 +22,7 @@ */ final class ListCommand extends DoctrineCommand { - /** @var string */ + /** @var string|null */ protected static $defaultName = 'migrations:list'; protected function configure(): void diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php index aa58197b66..13394258c5 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php @@ -30,7 +30,7 @@ */ final class MigrateCommand extends DoctrineCommand { - /** @var string */ + /** @var string|null */ protected static $defaultName = 'migrations:migrate'; protected function configure(): void diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/RollupCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/RollupCommand.php index ffb1811535..de14f1dc12 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/RollupCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/RollupCommand.php @@ -15,7 +15,7 @@ */ final class RollupCommand extends DoctrineCommand { - /** @var string */ + /** @var string|null */ protected static $defaultName = 'migrations:rollup'; protected function configure(): void diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/StatusCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/StatusCommand.php index 9f438b33ee..42d165e2ec 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/StatusCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/StatusCommand.php @@ -13,7 +13,7 @@ */ final class StatusCommand extends DoctrineCommand { - /** @var string */ + /** @var string|null */ protected static $defaultName = 'migrations:status'; protected function configure(): void diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/SyncMetadataCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/SyncMetadataCommand.php index f4bf03b5a5..e1ec07104d 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/SyncMetadataCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/SyncMetadataCommand.php @@ -9,7 +9,7 @@ final class SyncMetadataCommand extends DoctrineCommand { - /** @var string */ + /** @var string|null */ protected static $defaultName = 'migrations:sync-metadata-storage'; protected function configure(): void diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/UpToDateCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/UpToDateCommand.php index 1675e639ec..5849fcfc33 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/UpToDateCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/UpToDateCommand.php @@ -26,7 +26,7 @@ */ final class UpToDateCommand extends DoctrineCommand { - /** @var string */ + /** @var string|null */ protected static $defaultName = 'migrations:up-to-date'; protected function configure(): void diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/VersionCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/VersionCommand.php index 55527d83fc..45064c17b4 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/VersionCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/VersionCommand.php @@ -25,7 +25,7 @@ */ final class VersionCommand extends DoctrineCommand { - /** @var string */ + /** @var string|null */ protected static $defaultName = 'migrations:version'; /** @var bool */ diff --git a/phpstan-common.neon.dist b/phpstan-common.neon.dist index d49957daf3..3c45292446 100644 --- a/phpstan-common.neon.dist +++ b/phpstan-common.neon.dist @@ -24,6 +24,8 @@ parameters: message: '~^Method Doctrine\\Migrations\\Tests\\Stub\\DoctrineRegistry::getService\(\) should return Doctrine\\Persistence\\ObjectManager but returns Doctrine\\DBAL\\Connection\|Doctrine\\ORM\\EntityManager~' path: tests/Doctrine/Migrations/Tests/Stub/DoctrineRegistry.php + - '~^Property Doctrine\\Migrations\\Tests\\Provider\\\w+::\$id is never written, only read\.$~' + # https://github.com/phpstan/phpstan/issues/5982 - message: '~^Cannot call method getWrappedConnection\(\) on class-string\|object\.~' @@ -35,6 +37,11 @@ parameters: paths: - tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php + # TODO: Be more precise about class-strings + - + message: '~^Method Doctrine\\Migrations\\Version\\DbalMigrationFactory::createVersion\(\) should return Doctrine\\Migrations\\AbstractMigration but returns object\.$~' + paths: + - lib/Doctrine/Migrations/Version/DbalMigrationFactory.php symfony: console_application_loader: %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/doctrine-migrations-phpstan-app.php diff --git a/phpstan-dbal-2.neon.dist b/phpstan-dbal-2.neon.dist index 074e847fd1..bda8951e2c 100644 --- a/phpstan-dbal-2.neon.dist +++ b/phpstan-dbal-2.neon.dist @@ -35,3 +35,8 @@ parameters: - tests/Doctrine/Migrations/Tests/SchemaDumperTest.php - '~Trying to mock an undefined method getNativeConnection\(\) on class Doctrine\\DBAL\\Connection~' + + - + message: '~^Expression on left side of \?\? is not nullable\.$~' + paths: + - lib/Doctrine/Migrations/Tools/Console/Command/RollupCommand.php diff --git a/tests/Doctrine/Migrations/Tests/Event/Listeners/AutoCommitListenerTest.php b/tests/Doctrine/Migrations/Tests/Event/Listeners/AutoCommitListenerTest.php index 169079604f..6045adabad 100644 --- a/tests/Doctrine/Migrations/Tests/Event/Listeners/AutoCommitListenerTest.php +++ b/tests/Doctrine/Migrations/Tests/Event/Listeners/AutoCommitListenerTest.php @@ -52,7 +52,7 @@ public function testListenerDoesFinalCommitWhenAutoCommitIsOff(): void protected function setUp(): void { - $this->conn = $this->createStub(Connection::class); + $this->conn = $this->createMock(Connection::class); $driverConnection = $this->createStub(DriverConnection::class); $this->conn->method('getWrappedConnection')->willReturn($driverConnection); diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php index c2ef2d78dc..a945a93055 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php @@ -144,8 +144,8 @@ public function testExecutedUnavailableMigrationsCancel(): void protected function setUp(): void { - $this->migrationDiffGenerator = $this->createStub(DiffGenerator::class); - $this->migrationStatusCalculator = $this->createStub(MigrationStatusCalculator::class); + $this->migrationDiffGenerator = $this->createMock(DiffGenerator::class); + $this->migrationStatusCalculator = $this->createMock(MigrationStatusCalculator::class); $this->configuration = new Configuration(); $this->configuration->addMigrationsDirectory('FooNs', sys_get_temp_dir()); diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php index 9ccc3c1d99..be94168153 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php @@ -374,8 +374,9 @@ public function testExecuteMigrateDown(): void } /** - * @dataProvider allOrNothing * @psalm-param array $input + * + * @dataProvider allOrNothing */ public function testExecuteMigrateAllOrNothing(bool $default, array $input, bool $expected): void {