Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump Psalm level to 3 #4348

Merged
merged 21 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Cache/ResultCacheStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public function fetchAllNumeric(): array

$this->store($data);

return array_map('array_values', $this->data);
return array_map('array_values', $data);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function setResultCacheImpl(Cache $cacheImpl)
*
* @deprecated Use Configuration::setSchemaAssetsFilter() instead
*
* @param string $filterExpression
* @param string|null $filterExpression
*
* @return void
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
Expand All @@ -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());
}
}

Expand All @@ -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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
11 changes: 9 additions & 2 deletions lib/Doctrine/DBAL/Driver/IBMDB2/Exception/PrepareFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}
3 changes: 1 addition & 2 deletions lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
18 changes: 9 additions & 9 deletions lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/DBAL/DriverManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private function __construct()
* <b>driverClass</b>:
* The driver class to use.
*
* @param array{wrapperClass?: class-string<T>} $params
* @param array{wrapperClass?: class-string<T>} $params
* @param Configuration|null $config The configuration to use.
* @param EventManager|null $eventManager The event manager to use.
*
Expand Down Expand Up @@ -195,6 +195,7 @@ public static function getConnection(
throw Exception::invalidWrapperClass($params['wrapperClass']);
}

/** @var class-string<Connection> $wrapperClass */
$wrapperClass = $params['wrapperClass'];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class SchemaColumnDefinitionEventArgs extends SchemaEventArgs
{
/** @var Column|null */
private $column = null;
private $column;

/**
* Raw column data as fetched from the database.
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SchemaDropTableEventArgs extends SchemaEventArgs
private $platform;

/** @var string|null */
private $sql = null;
private $sql;

/**
* @param string|Table $table
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class SchemaIndexDefinitionEventArgs extends SchemaEventArgs
{
/** @var Index|null */
private $index = null;
private $index;

/**
* Raw index data as fetched from the database.
Expand Down
12 changes: 7 additions & 5 deletions lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ 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
* in reverse engineering scenarios.
*
* @var string[]|null
*/
protected $doctrineTypeComments = null;
protected $doctrineTypeComments;

/** @var EventManager */
protected $_eventManager;
Expand Down Expand Up @@ -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),
]);
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Loading