diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 502bb7240b0..35f1d6645a0 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -1,4 +1,3 @@ - name: "Static Analysis" on: @@ -34,7 +33,7 @@ jobs: uses: "ramsey/composer-install@v1" - name: "Run a static analysis with phpstan/phpstan" - run: "vendor/bin/phpstan analyse --error-format=checkstyle | cs2pr" + run: "vendor/bin/phpstan --error-format=checkstyle | cs2pr" static-analysis-psalm: name: "Static Analysis with Psalm" @@ -50,6 +49,6 @@ jobs: uses: actions/checkout@v2 - name: Psalm - uses: docker://vimeo/psalm-github-actions:4.5.2 + uses: docker://vimeo/psalm-github-actions:4.6.4 with: composer_require_dev: true diff --git a/composer.json b/composer.json index 62098888a52..96658ce03cb 100644 --- a/composer.json +++ b/composer.json @@ -34,17 +34,18 @@ "php": "^7.3 || ^8.0", "composer/package-versions-deprecated": "^1.11.99", "doctrine/cache": "^1.0", + "doctrine/deprecations": "^0.5.3", "doctrine/event-manager": "^1.0" }, "require-dev": { "doctrine/coding-standard": "8.2.0", - "jetbrains/phpstorm-stubs": "2019.3", - "phpstan/phpstan": "0.12.80", + "jetbrains/phpstorm-stubs": "2020.2", + "phpstan/phpstan": "0.12.81", "phpstan/phpstan-strict-rules": "^0.12.2", "phpunit/phpunit": "9.5.0", "psalm/plugin-phpunit": "0.13.0", "symfony/console": "^2.0.5|^3.0|^4.0|^5.0", - "vimeo/psalm": "4.5.2" + "vimeo/psalm": "4.6.4" }, "suggest": { "symfony/console": "For helpful console commands such as SQL execution and import of files." diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 33ba7169315..d7aa7887cf4 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -16,7 +16,7 @@ parameters: - '~^Return type \(int\|false\) of method Doctrine\\DBAL\\Driver\\OCI8\\Connection\:\:lastInsertId\(\) should be compatible with return type \(string\) of method Doctrine\\DBAL\\Driver\\Connection::lastInsertId\(\)~' - '~^Method Doctrine\\DBAL\\Driver\\Mysqli\\Connection::lastInsertId\(\) should return string but returns int\|string\.$~' - # https://github.com/phpstan/phpstan/issues/2857 + # https://github.com/doctrine/dbal/pull/3836 # TODO: remove in 4.0.0 - '~^Parameter #2 \$registeredAliases of static method Doctrine\\DBAL\\Query\\QueryException::nonUniqueAlias\(\) expects array, array given\.\z~' @@ -30,11 +30,6 @@ parameters: # weird class name, represented in stubs as OCI_(Lob|Collection) - '~unknown class OCI-(Lob|Collection)~' - # https://github.com/phpstan/phpstan/issues/3132 - - - message: '~^Call to function in_array\(\) with arguments Doctrine\\DBAL\\Schema\\Column, array and true will always evaluate to false\.$~' - path: %currentWorkingDirectory%/src/Schema/Table.php - # Requires a release of https://github.com/JetBrains/phpstorm-stubs/pull/553 - message: '~^Call to function assert\(\) with true will always evaluate to true\.$~' @@ -89,13 +84,6 @@ parameters: paths: - %currentWorkingDirectory%/src/Platforms/SQLServer2012Platform.php - # Caused by phpdoc annotations intended for Psalm - - - message: '~Unable to resolve the template type T in call to method static method Doctrine\\DBAL\\DriverManager::getConnection\(\)~' - paths: - - %currentWorkingDirectory%/src/Id/TableGenerator.php - - %currentWorkingDirectory%/src/Schema/SqliteSchemaManager.php - # Unlike Psalm, PHPStan doesn't understand the shape of the parse_str() return value - message: '~^Parameter #1 \$scheme of static method Doctrine\\DBAL\\DriverManager::parseDatabaseUrlScheme\(\) expects string\|null, int\|string\|null given\.$~' diff --git a/psalm.xml.dist b/psalm.xml.dist index fed54d66a62..d19deca8322 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -227,7 +227,8 @@ --> @@ -241,15 +242,6 @@ - - - - - - diff --git a/src/Event/SchemaAlterTableAddColumnEventArgs.php b/src/Event/SchemaAlterTableAddColumnEventArgs.php index 30a1a9ca78a..e61a48d064c 100644 --- a/src/Event/SchemaAlterTableAddColumnEventArgs.php +++ b/src/Event/SchemaAlterTableAddColumnEventArgs.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\TableDiff; +use Doctrine\Deprecations\Deprecation; use function array_merge; use function func_get_args; @@ -67,6 +68,15 @@ public function getPlatform() */ public function addSql($sql) { + if (is_array($sql)) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'Passing multiple SQL statements as an array to SchemaAlterTableAddColumnEventaArrgs::addSql() ' . + 'is deprecated. Pass each statement as an individual argument instead.' + ); + } + $this->sql = array_merge($this->sql, is_array($sql) ? $sql : func_get_args()); return $this; diff --git a/src/Platforms/AbstractPlatform.php b/src/Platforms/AbstractPlatform.php index 15dced5e488..59bf8f04ace 100644 --- a/src/Platforms/AbstractPlatform.php +++ b/src/Platforms/AbstractPlatform.php @@ -30,6 +30,7 @@ use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\Types; use Doctrine\DBAL\Types\Type; +use Doctrine\Deprecations\Deprecation; use InvalidArgumentException; use UnexpectedValueException; @@ -58,9 +59,6 @@ use function strpos; use function strtolower; use function strtoupper; -use function trigger_error; - -use const E_USER_DEPRECATED; /** * Base class for all DatabasePlatforms. The DatabasePlatforms are the central @@ -245,12 +243,14 @@ public function getBinaryTypeDeclarationSQL(array $column) if ($column['length'] > $maxLength) { if ($maxLength > 0) { - @trigger_error(sprintf( + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3187', 'Binary column length %d is greater than supported by the platform (%d).' . ' Reduce the column length or use a BLOB column instead.', $column['length'], $maxLength - ), E_USER_DEPRECATED); + ); } return $this->getBlobTypeDeclarationSQL($column); diff --git a/src/Query/Expression/CompositeExpression.php b/src/Query/Expression/CompositeExpression.php index 4e551e95429..a1808b1ee8f 100644 --- a/src/Query/Expression/CompositeExpression.php +++ b/src/Query/Expression/CompositeExpression.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Query\Expression; use Countable; +use Doctrine\Deprecations\Deprecation; use function array_merge; use function count; @@ -48,6 +49,12 @@ public function __construct($type, array $parts = []) $this->type = $type; $this->addMultiple($parts); + + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3864', + 'Do not use CompositeExpression constructor directly, use static and() and or() factory methods.' + ); } /** @@ -79,6 +86,12 @@ public static function or($part, ...$parts): self */ public function addMultiple(array $parts = []) { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3844', + 'CompositeExpression::addMultiple() is deprecated, use CompositeExpression::with() instead.' + ); + foreach ($parts as $part) { $this->add($part); } @@ -97,6 +110,12 @@ public function addMultiple(array $parts = []) */ public function add($part) { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3844', + 'CompositeExpression::add() is deprecated, use CompositeExpression::with() instead.' + ); + if ($part === null) { return $this; } diff --git a/src/Query/Expression/ExpressionBuilder.php b/src/Query/Expression/ExpressionBuilder.php index f12ef0fa5f1..c86cfc32492 100644 --- a/src/Query/Expression/ExpressionBuilder.php +++ b/src/Query/Expression/ExpressionBuilder.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Query\Expression; use Doctrine\DBAL\Connection; +use Doctrine\Deprecations\Deprecation; use function func_get_arg; use function func_get_args; @@ -71,6 +72,12 @@ public function or($expression, ...$expressions): CompositeExpression */ public function andX($x = null) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3851', + 'ExpressionBuilder::andX() is deprecated, use ExpressionBuilder::and() instead.' + ); + return new CompositeExpression(CompositeExpression::TYPE_AND, func_get_args()); } @@ -84,6 +91,12 @@ public function andX($x = null) */ public function orX($x = null) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3851', + 'ExpressionBuilder::orX() is deprecated, use ExpressionBuilder::or() instead.' + ); + return new CompositeExpression(CompositeExpression::TYPE_OR, func_get_args()); } diff --git a/src/Query/QueryBuilder.php b/src/Query/QueryBuilder.php index 92cd2157723..3d51a44cc55 100644 --- a/src/Query/QueryBuilder.php +++ b/src/Query/QueryBuilder.php @@ -10,6 +10,7 @@ use Doctrine\DBAL\Result; use Doctrine\DBAL\Statement; use Doctrine\DBAL\Types\Type; +use Doctrine\Deprecations\Deprecation; use function array_key_exists; use function array_keys; @@ -269,7 +270,7 @@ public function getSQL() * * @param int|string $key Parameter position or name * @param mixed $value Parameter value - * @param int|string|Type|null $type One of the {@link ParameterType} constants or DBAL type + * @param int|string|Type|null $type Parameter type * * @return $this This QueryBuilder instance. */ @@ -483,6 +484,15 @@ public function select($select = null/*, string ...$selects*/) return $this; } + if (is_array($select)) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3837', + 'Passing an array for the first argument to QueryBuilder::select is deprecated, ' . + 'pass each value as an individual variadic argument instead.' + ); + } + $selects = is_array($select) ? $select : func_get_args(); return $this->add('select', $selects); @@ -533,6 +543,15 @@ public function addSelect($select = null/*, string ...$selects*/) return $this; } + if (is_array($select)) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3837', + 'Passing an array for the first argument to QueryBuilder::addSelect is deprecated, ' . + 'pass each value as an individual variadic argument instead.' + ); + } + $selects = is_array($select) ? $select : func_get_args(); return $this->add('select', $selects, true); @@ -905,6 +924,15 @@ public function groupBy($groupBy/*, string ...$groupBys*/) return $this; } + if (is_array($groupBy)) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3837', + 'Passing an array for the first argument to QueryBuilder::groupBy is deprecated, ' . + 'pass each value as an individual variadic argument instead.' + ); + } + $groupBy = is_array($groupBy) ? $groupBy : func_get_args(); return $this->add('groupBy', $groupBy, false); @@ -934,6 +962,15 @@ public function addGroupBy($groupBy/*, string ...$groupBys*/) return $this; } + if (is_array($groupBy)) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3837', + 'Passing an array for the first argument to QueryBuilder::addGroupBy is deprecated, ' . + 'pass each value as an individual variadic argument instead.' + ); + } + $groupBy = is_array($groupBy) ? $groupBy : func_get_args(); return $this->add('groupBy', $groupBy, true); diff --git a/src/Schema/AbstractSchemaManager.php b/src/Schema/AbstractSchemaManager.php index a6deb5e76c6..b53909149b9 100644 --- a/src/Schema/AbstractSchemaManager.php +++ b/src/Schema/AbstractSchemaManager.php @@ -8,6 +8,7 @@ use Doctrine\DBAL\Events; use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\Deprecations\Deprecation; use Throwable; use function array_filter; @@ -19,6 +20,7 @@ use function count; use function func_get_args; use function is_callable; +use function is_string; use function preg_match; use function str_replace; use function strtolower; @@ -205,6 +207,15 @@ public function listTableIndexes($table) */ public function tablesExist($names) { + if (is_string($names)) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'The usage of a string $tableNames in AbstractSchemaManager::tablesExist is deprecated. ' . + 'Pass a one-element array instead.' + ); + } + $names = array_map('strtolower', (array) $names); return count($names) === count(array_intersect($names, array_map('strtolower', $this->listTableNames()))); diff --git a/src/Tools/Console/Command/RunSqlCommand.php b/src/Tools/Console/Command/RunSqlCommand.php index a4ba7d3bda4..4ccb3260547 100644 --- a/src/Tools/Console/Command/RunSqlCommand.php +++ b/src/Tools/Console/Command/RunSqlCommand.php @@ -44,7 +44,7 @@ protected function configure() ->setDefinition([ new InputOption('connection', null, InputOption::VALUE_REQUIRED, 'The named database connection'), new InputArgument('sql', InputArgument::REQUIRED, 'The SQL statement to execute.'), - new InputOption('depth', null, InputOption::VALUE_REQUIRED, 'Dumping depth of result set.', 7), + new InputOption('depth', null, InputOption::VALUE_REQUIRED, 'Dumping depth of result set.', '7'), new InputOption('force-fetch', null, InputOption::VALUE_NONE, 'Forces fetching the result.'), ]) ->setHelp(<<