diff --git a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php index 34381e23b1c..07a6c220611 100644 --- a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php +++ b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php @@ -244,7 +244,7 @@ public function fetchAllNumeric(): array $this->store($data); - return array_map('array_values', $this->data); + return array_map('array_values', $data); } /** diff --git a/lib/Doctrine/DBAL/Configuration.php b/lib/Doctrine/DBAL/Configuration.php index 6d2497b632d..545b0ffb0b4 100644 --- a/lib/Doctrine/DBAL/Configuration.php +++ b/lib/Doctrine/DBAL/Configuration.php @@ -73,7 +73,7 @@ public function setResultCacheImpl(Cache $cacheImpl) * * @deprecated Use Configuration::setSchemaAssetsFilter() instead * - * @param string $filterExpression + * @param string|null $filterExpression * * @return void */ diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php index dc2701e344a..bdc52551f52 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php @@ -37,7 +37,7 @@ class DB2Connection implements ConnectionInterface, ServerInfoAwareConnection { /** @var resource */ - private $conn = null; + private $conn; /** * @internal The connection can be only instantiated by its driver. @@ -93,7 +93,7 @@ public function prepare($sql) $stmt = @db2_prepare($this->conn, $sql); if ($stmt === false) { - throw PrepareFailed::new(error_get_last()['message']); + throw PrepareFailed::new(error_get_last()); } return new Statement($stmt); diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index 02cc6526907..c758a253d0a 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -455,9 +455,9 @@ public function free(): void /** * Casts a stdClass object to the given class name mapping its' properties. * - * @param stdClass $sourceObject Object to cast from. - * @param string|object $destinationClass Name of the class or class instance to cast to. - * @param mixed[] $ctorArgs Arguments to use for constructing the destination class instance. + * @param stdClass $sourceObject Object to cast from. + * @param class-string|object $destinationClass Name of the class or class instance to cast to. + * @param mixed[] $ctorArgs Arguments to use for constructing the destination class instance. * * @return object * @@ -527,7 +527,7 @@ private function createTemporaryFile() $handle = @tmpfile(); if ($handle === false) { - throw CannotCreateTemporaryFile::new(error_get_last()['message']); + throw CannotCreateTemporaryFile::new(error_get_last()); } return $handle; @@ -542,7 +542,7 @@ private function createTemporaryFile() private function copyStreamToStream($source, $target): void { if (@stream_copy_to_stream($source, $target) === false) { - throw CannotCopyStreamToStream::new(error_get_last()['message']); + throw CannotCopyStreamToStream::new(error_get_last()); } } @@ -554,7 +554,7 @@ private function copyStreamToStream($source, $target): void private function writeStringToStream(string $string, $target): void { if (@fwrite($target, $string) === false) { - throw CannotWriteToTemporaryFile::new(error_get_last()['message']); + throw CannotWriteToTemporaryFile::new(error_get_last()); } } } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCopyStreamToStream.php b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCopyStreamToStream.php index 8223a92d660..61244c1cc61 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCopyStreamToStream.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCopyStreamToStream.php @@ -13,8 +13,17 @@ */ final class CannotCopyStreamToStream extends DB2Exception { - public static function new(string $message): self + /** + * @psalm-param array{message: string}|null $error + */ + public static function new(?array $error): self { - return new self('Could not copy source stream to temporary file: ' . $message); + $message = 'Could not copy source stream to temporary file'; + + if ($error !== null) { + $message .= ': ' . $error['message']; + } + + return new self($message); } } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCreateTemporaryFile.php b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCreateTemporaryFile.php index 48b28dd33d3..d5481ed9e31 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCreateTemporaryFile.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCreateTemporaryFile.php @@ -13,8 +13,17 @@ */ final class CannotCreateTemporaryFile extends DB2Exception { - public static function new(string $message): self + /** + * @psalm-param array{message: string}|null $error + */ + public static function new(?array $error): self { - return new self('Could not create temporary file: ' . $message); + $message = 'Could not create temporary file'; + + if ($error !== null) { + $message .= ': ' . $error['message']; + } + + return new self($message); } } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotWriteToTemporaryFile.php b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotWriteToTemporaryFile.php index 8acc269a4ad..33d0b86cc4f 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotWriteToTemporaryFile.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotWriteToTemporaryFile.php @@ -13,8 +13,17 @@ */ final class CannotWriteToTemporaryFile extends DB2Exception { - public static function new(string $message): self + /** + * @psalm-param array{message: string}|null $error + */ + public static function new(?array $error): self { - return new self('Could not write string to temporary file: ' . $message); + $message = 'Could not write string to temporary file'; + + if ($error !== null) { + $message .= ': ' . $error['message']; + } + + return new self($message); } } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/PrepareFailed.php b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/PrepareFailed.php index f566df8d50d..035fd67f9c2 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/PrepareFailed.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/PrepareFailed.php @@ -13,8 +13,15 @@ */ final class PrepareFailed extends AbstractException { - public static function new(string $message): self + /** + * @psalm-param array{message: string}|null $error + */ + public static function new(?array $error): self { - return new self($message); + if ($error === null) { + return new self('Unknown error'); + } + + return new self($error['message']); } } diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index d019d74576f..cbb8a851b27 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -299,8 +299,7 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le if ($type === ParameterType::LARGE_OBJECT) { $lob = oci_new_descriptor($this->_dbh, OCI_D_LOB); - $class = 'OCI-Lob'; - assert($lob instanceof $class); + assert($lob !== false); $lob->writeTemporary($variable, OCI_TEMP_BLOB); diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php index 95b59274e9e..81d88232dca 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php @@ -52,15 +52,15 @@ public function getName() /** * Build the connection string for given connection parameters and driver options. * - * @param string $host Host address to connect to. - * @param int $port Port to use for the connection (default to SQL Anywhere standard port 2638). - * @param string $server Database server name on the host to connect to. - * SQL Anywhere allows multiple database server instances on the same host, - * therefore specifying the server instance name to use is mandatory. - * @param string $dbname Name of the database on the server instance to connect to. - * @param string $username User name to use for connection authentication. - * @param string $password Password to use for connection authentication. - * @param mixed[] $driverOptions Additional parameters to use for the connection. + * @param string|null $host Host address to connect to. + * @param int|null $port Port to use for the connection (default to SQL Anywhere standard port 2638). + * @param string|null $server Database server name on the host to connect to. + * SQL Anywhere allows multiple database server instances on the same host, + * therefore specifying the server instance name to use is mandatory. + * @param string|null $dbname Name of the database on the server instance to connect to. + * @param string $username User name to use for connection authentication. + * @param string $password Password to use for connection authentication. + * @param mixed[] $driverOptions Additional parameters to use for the connection. * * @return string */ diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php index 1542276dba2..513e4a508ef 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -419,9 +419,9 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) /** * Casts a stdClass object to the given class name mapping its' properties. * - * @param stdClass $sourceObject Object to cast from. - * @param string|object $destinationClass Name of the class or class instance to cast to. - * @param mixed[] $ctorArgs Arguments to use for constructing the destination class instance. + * @param stdClass $sourceObject Object to cast from. + * @param class-string|object $destinationClass Name of the class or class instance to cast to. + * @param mixed[] $ctorArgs Arguments to use for constructing the destination class instance. * * @return object * diff --git a/lib/Doctrine/DBAL/DriverManager.php b/lib/Doctrine/DBAL/DriverManager.php index 5b12e4871bb..17ba8584da2 100644 --- a/lib/Doctrine/DBAL/DriverManager.php +++ b/lib/Doctrine/DBAL/DriverManager.php @@ -113,7 +113,7 @@ private function __construct() * driverClass: * The driver class to use. * - * @param array{wrapperClass?: class-string} $params + * @param array{wrapperClass?: class-string} $params * @param Configuration|null $config The configuration to use. * @param EventManager|null $eventManager The event manager to use. * @@ -195,6 +195,7 @@ public static function getConnection( throw Exception::invalidWrapperClass($params['wrapperClass']); } + /** @var class-string $wrapperClass */ $wrapperClass = $params['wrapperClass']; } diff --git a/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php index 2be445e38af..7c962a928f4 100644 --- a/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php @@ -12,7 +12,7 @@ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs { /** @var Column|null */ - private $column = null; + private $column; /** * Raw column data as fetched from the database. diff --git a/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php index 1236de401ab..072e1efb909 100644 --- a/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php @@ -18,7 +18,7 @@ class SchemaDropTableEventArgs extends SchemaEventArgs private $platform; /** @var string|null */ - private $sql = null; + private $sql; /** * @param string|Table $table diff --git a/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php index ca6bbf81f7e..055a19a7c27 100644 --- a/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php @@ -12,7 +12,7 @@ class SchemaIndexDefinitionEventArgs extends SchemaEventArgs { /** @var Index|null */ - private $index = null; + private $index; /** * Raw index data as fetched from the database. diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index ba551574651..911daa8cb8b 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -132,7 +132,7 @@ abstract class AbstractPlatform public const TRIM_BOTH = TrimMode::BOTH; /** @var string[]|null */ - protected $doctrineTypeMapping = null; + protected $doctrineTypeMapping; /** * Contains a list of all columns that should generate parseable column comments for type-detection @@ -140,7 +140,7 @@ abstract class AbstractPlatform * * @var string[]|null */ - protected $doctrineTypeComments = null; + protected $doctrineTypeComments; /** @var EventManager */ protected $_eventManager; @@ -1602,8 +1602,10 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE } } + $name = $column->getQuotedName($this); + $columnData = array_merge($column->toArray(), [ - 'name' => $column->getQuotedName($this), + 'name' => $name, 'version' => $column->hasPlatformOption('version') ? $column->getPlatformOption('version') : false, 'comment' => $this->getColumnComment($column), ]); @@ -1616,7 +1618,7 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE $columnData['primary'] = true; } - $columns[$columnData['name']] = $columnData; + $columns[$name] = $columnData; } if (($createFlags & self::CREATE_FOREIGNKEYS) > 0) { @@ -1742,7 +1744,7 @@ protected function _getCreateTableSQL($name, array $columns, array $options = [] $query .= ')'; - $sql[] = $query; + $sql = [$query]; if (isset($options['foreignKeys'])) { foreach ((array) $options['foreignKeys'] as $definition) { diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php b/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php index 860d9f21099..852a58aba2b 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php @@ -12,7 +12,7 @@ abstract class KeywordList { /** @var string[]|null */ - private $keywords = null; + private $keywords; /** * Checks if the given word is a keyword of this dialect/vendor platform. diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 2b45883b3fa..b41f33bef46 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -1199,10 +1199,10 @@ public function getAsciiStringTypeDeclarationSQL(array $column): string $length = $column['length'] ?? null; if (! isset($column['fixed'])) { - return sprintf('VARCHAR(%d)', $length); + return sprintf('VARCHAR(%d)', $length ?? 255); } - return sprintf('CHAR(%d)', $length); + return sprintf('CHAR(%d)', $length ?? 255); } /** diff --git a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php index c33970fc142..e42a6bd89ec 100644 --- a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php @@ -719,7 +719,9 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) */ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) { - if (! $diff->fromTable instanceof Table) { + $fromTable = $diff->fromTable; + + if (! $fromTable instanceof Table) { throw new Exception( 'Sqlite platform requires for alter table the table diff with reference to original table schema' ); @@ -732,7 +734,7 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) $tableName = $diff->getName($this); } - foreach ($this->getIndexesInAlteredTable($diff) as $index) { + foreach ($this->getIndexesInAlteredTable($diff, $fromTable) as $index) { if ($index->isPrimary()) { continue; } @@ -952,8 +954,8 @@ public function getAlterTableSQL(TableDiff $diff) $newTable = new Table( $table->getQuotedName($this), $columns, - $this->getPrimaryIndexInAlteredTable($diff), - $this->getForeignKeysInAlteredTable($diff), + $this->getPrimaryIndexInAlteredTable($diff, $fromTable), + $this->getForeignKeysInAlteredTable($diff, $fromTable), 0, $table->getOptions() ); @@ -1092,11 +1094,11 @@ private function getSimpleAlterTableSQL(TableDiff $diff) /** * @return string[] */ - private function getColumnNamesInAlteredTable(TableDiff $diff) + private function getColumnNamesInAlteredTable(TableDiff $diff, Table $fromTable) { $columns = []; - foreach ($diff->fromTable->getColumns() as $columnName => $column) { + foreach ($fromTable->getColumns() as $columnName => $column) { $columns[strtolower($columnName)] = $column->getName(); } @@ -1132,10 +1134,10 @@ private function getColumnNamesInAlteredTable(TableDiff $diff) /** * @return Index[] */ - private function getIndexesInAlteredTable(TableDiff $diff) + private function getIndexesInAlteredTable(TableDiff $diff, Table $fromTable) { - $indexes = $diff->fromTable->getIndexes(); - $columnNames = $this->getColumnNamesInAlteredTable($diff); + $indexes = $fromTable->getIndexes(); + $columnNames = $this->getColumnNamesInAlteredTable($diff, $fromTable); foreach ($indexes as $key => $index) { foreach ($diff->renamedIndexes as $oldIndexName => $renamedIndex) { @@ -1200,10 +1202,10 @@ private function getIndexesInAlteredTable(TableDiff $diff) /** * @return ForeignKeyConstraint[] */ - private function getForeignKeysInAlteredTable(TableDiff $diff) + private function getForeignKeysInAlteredTable(TableDiff $diff, Table $fromTable) { - $foreignKeys = $diff->fromTable->getForeignKeys(); - $columnNames = $this->getColumnNamesInAlteredTable($diff); + $foreignKeys = $fromTable->getForeignKeys(); + $columnNames = $this->getColumnNamesInAlteredTable($diff, $fromTable); foreach ($foreignKeys as $key => $constraint) { $changed = false; @@ -1264,11 +1266,11 @@ private function getForeignKeysInAlteredTable(TableDiff $diff) /** * @return Index[] */ - private function getPrimaryIndexInAlteredTable(TableDiff $diff) + private function getPrimaryIndexInAlteredTable(TableDiff $diff, Table $fromTable) { $primaryIndex = []; - foreach ($this->getIndexesInAlteredTable($diff) as $index) { + foreach ($this->getIndexesInAlteredTable($diff, $fromTable) as $index) { if (! $index->isPrimary()) { continue; } diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index c0c0ea58451..492a06951bb 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -119,14 +119,14 @@ class QueryBuilder * * @var int */ - private $firstResult = null; + private $firstResult; /** * The maximum number of results to retrieve or NULL to retrieve all results. * * @var int|null */ - private $maxResults = null; + private $maxResults; /** * The counter of bound parameters used with {@see bindValue). diff --git a/lib/Doctrine/DBAL/Schema/AbstractAsset.php b/lib/Doctrine/DBAL/Schema/AbstractAsset.php index 3424b17c544..02111832e26 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractAsset.php +++ b/lib/Doctrine/DBAL/Schema/AbstractAsset.php @@ -31,7 +31,7 @@ abstract class AbstractAsset * * @var string|null */ - protected $_namespace = null; + protected $_namespace; /** @var bool */ protected $_quoted = false; diff --git a/lib/Doctrine/DBAL/Schema/Column.php b/lib/Doctrine/DBAL/Schema/Column.php index e33f285108b..f63bcc9226b 100644 --- a/lib/Doctrine/DBAL/Schema/Column.php +++ b/lib/Doctrine/DBAL/Schema/Column.php @@ -21,7 +21,7 @@ class Column extends AbstractAsset protected $_type; /** @var int|null */ - protected $_length = null; + protected $_length; /** @var int */ protected $_precision = 10; @@ -39,7 +39,7 @@ class Column extends AbstractAsset protected $_notnull = true; /** @var string|null */ - protected $_default = null; + protected $_default; /** @var bool */ protected $_autoincrement = false; @@ -48,10 +48,10 @@ class Column extends AbstractAsset protected $_platformOptions = []; /** @var string|null */ - protected $_columnDefinition = null; + protected $_columnDefinition; /** @var string|null */ - protected $_comment = null; + protected $_comment; /** @var mixed[] */ protected $_customSchemaOptions = []; diff --git a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php index 25f0282c536..fcc196ae519 100644 --- a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php @@ -7,7 +7,6 @@ use function array_change_key_case; use function assert; -use function is_resource; use function preg_match; use function str_replace; use function strpos; @@ -207,13 +206,12 @@ protected function _getPortableForeignKeyRuleDef($def) protected function _getPortableViewDefinition($view) { $view = array_change_key_case($view, CASE_LOWER); - // sadly this still segfaults on PDO_IBM, see http://pecl.php.net/bugs/bug.php?id=17199 - //$view['text'] = (is_resource($view['text']) ? stream_get_contents($view['text']) : $view['text']); - if (! is_resource($view['text'])) { - $pos = strpos($view['text'], ' AS '); + + $sql = ''; + $pos = strpos($view['text'], ' AS '); + + if ($pos !== false) { $sql = substr($view['text'], $pos + 4); - } else { - $sql = ''; } return new View($view['name'], $sql); diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index d9fabec1660..e64a9c81735 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -60,7 +60,11 @@ public function getSchemaNames() public function getSchemaSearchPaths() { $params = $this->_conn->getParams(); - $schema = explode(',', $this->_conn->fetchColumn('SHOW search_path')); + + $searchPaths = $this->_conn->fetchColumn('SHOW search_path'); + assert($searchPaths !== false); + + $schema = explode(',', $searchPaths); if (isset($params['user'])) { $schema = str_replace('"$user"', $params['user'], $schema); @@ -150,13 +154,17 @@ protected function _getPortableTableForeignKeyDefinition($tableForeignKey) $onDelete = $match[1]; } - if (preg_match('/FOREIGN KEY \((.+)\) REFERENCES (.+)\((.+)\)/', $tableForeignKey['condef'], $values)) { - // PostgreSQL returns identifiers that are keywords with quotes, we need them later, don't get - // the idea to trim them here. - $localColumns = array_map('trim', explode(',', $values[1])); - $foreignColumns = array_map('trim', explode(',', $values[3])); - $foreignTable = $values[2]; - } + assert(preg_match( + '/FOREIGN KEY \((.+)\) REFERENCES (.+)\((.+)\)/', + $tableForeignKey['condef'], + $values + ) !== 0); + + // PostgreSQL returns identifiers that are keywords with quotes, we need them later, don't get + // the idea to trim them here. + $localColumns = array_map('trim', explode(',', $values[1])); + $foreignColumns = array_map('trim', explode(',', $values[3])); + $foreignTable = $values[2]; return new ForeignKeyConstraint( $localColumns, diff --git a/lib/Doctrine/DBAL/Schema/Schema.php b/lib/Doctrine/DBAL/Schema/Schema.php index 6ea5fd0c8c0..24fc47b599b 100644 --- a/lib/Doctrine/DBAL/Schema/Schema.php +++ b/lib/Doctrine/DBAL/Schema/Schema.php @@ -52,7 +52,7 @@ class Schema extends AbstractAsset protected $_sequences = []; /** @var SchemaConfig */ - protected $_schemaConfig = false; + protected $_schemaConfig; /** * @param Table[] $tables diff --git a/lib/Doctrine/DBAL/Schema/Sequence.php b/lib/Doctrine/DBAL/Schema/Sequence.php index 19dec9cd57a..1cba86c086c 100644 --- a/lib/Doctrine/DBAL/Schema/Sequence.php +++ b/lib/Doctrine/DBAL/Schema/Sequence.php @@ -19,7 +19,7 @@ class Sequence extends AbstractAsset protected $initialValue = 1; /** @var int|null */ - protected $cache = null; + protected $cache; /** * @param string $name diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index bd0462151a4..d69dc45f189 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -29,7 +29,7 @@ class Table extends AbstractAsset /** @var Index[] */ protected $_indexes = []; - /** @var string */ + /** @var string|false */ protected $_primaryKeyName = false; /** @var ForeignKeyConstraint[] */ @@ -41,7 +41,7 @@ class Table extends AbstractAsset ]; /** @var SchemaConfig|null */ - protected $_schemaConfig = null; + protected $_schemaConfig; /** * @param string $name @@ -150,6 +150,10 @@ public function addIndex(array $columnNames, $indexName = null, array $flags = [ */ public function dropPrimaryKey() { + if ($this->_primaryKeyName === false) { + return; + } + $this->dropIndex($this->_primaryKeyName); $this->_primaryKeyName = false; } @@ -717,11 +721,11 @@ public function getColumn($name) */ public function getPrimaryKey() { - if (! $this->hasPrimaryKey()) { - return null; + if ($this->_primaryKeyName !== false) { + return $this->getIndex($this->_primaryKeyName); } - return $this->getIndex($this->_primaryKeyName); + return null; } /** diff --git a/lib/Doctrine/DBAL/Schema/TableDiff.php b/lib/Doctrine/DBAL/Schema/TableDiff.php index dcaeb200a6a..82c912f71b1 100644 --- a/lib/Doctrine/DBAL/Schema/TableDiff.php +++ b/lib/Doctrine/DBAL/Schema/TableDiff.php @@ -10,7 +10,7 @@ class TableDiff { /** @var string */ - public $name = null; + public $name; /** @var string|false */ public $newName = false; diff --git a/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php b/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php index b2fab3ae4af..c08fb6fecd8 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php @@ -24,7 +24,7 @@ class CreateSchemaSqlCollector extends AbstractVisitor private $createFkConstraintQueries = []; /** @var AbstractPlatform */ - private $platform = null; + private $platform; public function __construct(AbstractPlatform $platform) { diff --git a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php index 7ea9ce1fad3..5fa2aa782eb 100644 --- a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php +++ b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php @@ -125,6 +125,8 @@ public function getDropAllSchema() $this->shardManager->selectGlobal(); $globalSql = $this->synchronizer->getDropAllSchema(); + $sql = []; + if ($globalSql) { $sql[] = "-- Work on Root Federation\nUSE FEDERATION ROOT WITH RESET;"; $sql = array_merge($sql, $globalSql); diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php index 3d53f342968..26456bde0ce 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php @@ -85,9 +85,14 @@ protected function execute(InputInterface $input, OutputInterface $output) $sql = @file_get_contents($filePath); if ($sql === false) { - throw new RuntimeException( - sprintf("Unable to read SQL file '%s': %s", $filePath, error_get_last()['message']) - ); + $message = sprintf("Unable to read SQL file '%s'", $filePath); + $error = error_get_last(); + + if ($error !== null) { + $message .= ': ' . $error['message']; + } + + throw new RuntimeException($message); } if ($conn instanceof PDOConnection) { diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php index 1888efdb619..bd819af0e6a 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Platforms\Keywords\DB2Keywords; +use Doctrine\DBAL\Platforms\Keywords\KeywordList; use Doctrine\DBAL\Platforms\Keywords\MySQL57Keywords; use Doctrine\DBAL\Platforms\Keywords\MySQL80Keywords; use Doctrine\DBAL\Platforms\Keywords\MySQLKeywords; @@ -41,7 +42,7 @@ class ReservedWordsCommand extends Command { - /** @var string[] */ + /** @var array> */ private $keywordListClasses = [ 'mysql' => MySQLKeywords::class, 'mysql57' => MySQL57Keywords::class, @@ -82,8 +83,8 @@ public function __construct(?ConnectionProvider $connectionProvider = null) /** * If you want to add or replace a keywords list use this command. * - * @param string $name - * @param string $class + * @param string $name + * @param class-string $class * * @return void */ diff --git a/lib/Doctrine/DBAL/Types/Type.php b/lib/Doctrine/DBAL/Types/Type.php index 5ff51c4c9bb..f8be9131bcd 100644 --- a/lib/Doctrine/DBAL/Types/Type.php +++ b/lib/Doctrine/DBAL/Types/Type.php @@ -236,8 +236,8 @@ public static function getType($name) /** * Adds a custom type to the type map. * - * @param string $name The name of the type. This should correspond to what getName() returns. - * @param string $className The class name of the custom type. + * @param string $name The name of the type. This should correspond to what getName() returns. + * @param class-string $className The class name of the custom type. * * @return void * @@ -263,8 +263,8 @@ public static function hasType($name) /** * Overrides an already defined type to use a different implementation. * - * @param string $name - * @param string $className + * @param string $name + * @param class-string $className * * @return void * diff --git a/psalm.xml b/psalm.xml index f67b67c6566..999a5611126 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,7 +1,7 @@ + + + + + + + + + + + + + + +