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

[SCA] Minor improvement on Psalm typing #6003

Merged
merged 1 commit into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 src/ArrayParameterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class ArrayParameterType
/**
* @internal
*
* @psalm-param self::INTEGER|self::STRING|self::ASCII $type
* @psalm-param self::* $type
*
* @psalm-return ParameterType::INTEGER|ParameterType::STRING|ParameterType::ASCII
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Driver/PDO/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Doctrine\DBAL\Driver\PDO;

use Doctrine\DBAL\Driver\Exception\UnknownParameterType;
use Doctrine\DBAL\Driver\PDO\PDOException as DriverPDOException;
use Doctrine\DBAL\Driver\Result as ResultInterface;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
Expand Down Expand Up @@ -78,6 +79,10 @@ public function query(string $sql): ResultInterface

/**
* {@inheritdoc}
*
* @throws UnknownParameterType
*
* @psalm-assert ParameterType::* $type
*/
public function quote($value, $type = ParameterType::STRING)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Driver/PDO/ParameterTypeMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ final class ParameterTypeMap
* @psalm-return PDO::PARAM_*
*
* @throws UnknownParameterType
*
* @psalm-assert ParameterType::* $type
*/
public static function convertParamType(int $type): int
{
Expand Down
9 changes: 9 additions & 0 deletions src/Driver/PDO/SQLSrv/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Doctrine\DBAL\Driver\PDO\SQLSrv;

use Doctrine\DBAL\Driver\Exception\UnknownParameterType;
use Doctrine\DBAL\Driver\Middleware\AbstractStatementMiddleware;
use Doctrine\DBAL\Driver\PDO\Statement as PDOStatement;
use Doctrine\DBAL\ParameterType;
Expand Down Expand Up @@ -32,6 +33,10 @@ public function __construct(PDOStatement $statement)
* @param int $type
* @param int|null $length
* @param mixed $driverOptions The usage of the argument is deprecated.
*
* @throws UnknownParameterType
*
* @psalm-assert ParameterType::* $type
*/
public function bindParam(
$param,
Expand Down Expand Up @@ -82,7 +87,11 @@ public function bindParam(
}

/**
* @throws UnknownParameterType
*
* {@inheritdoc}
*
* @psalm-assert ParameterType::* $type
*/
public function bindValue($param, $value, $type = ParameterType::STRING): bool
{
Expand Down
9 changes: 9 additions & 0 deletions src/Driver/PDO/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Doctrine\DBAL\Driver\PDO;

use Doctrine\DBAL\Driver\Exception\UnknownParameterType;
use Doctrine\DBAL\Driver\Result as ResultInterface;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
use Doctrine\DBAL\ParameterType;
Expand All @@ -25,6 +26,10 @@ public function __construct(PDOStatement $stmt)

/**
* {@inheritdoc}
*
* @throws UnknownParameterType
*
* @psalm-assert ParameterType::* $type
*/
public function bindValue($param, $value, $type = ParameterType::STRING)
{
Expand Down Expand Up @@ -56,6 +61,10 @@ public function bindValue($param, $value, $type = ParameterType::STRING)
* @param int $type
* @param int|null $length
* @param mixed $driverOptions The usage of the argument is deprecated.
*
* @throws UnknownParameterType
*
* @psalm-assert ParameterType::* $type
*/
public function bindParam(
$param,
Expand Down
21 changes: 19 additions & 2 deletions src/Driver/SQLite3/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ public function __construct(SQLite3 $connection, SQLite3Stmt $statement)
$this->statement = $statement;
}

/** @inheritdoc */
/**
* @throws UnknownParameterType
*
* {@inheritdoc}
*
* @psalm-assert ParameterType::* $type
*/
public function bindValue($param, $value, $type = ParameterType::STRING): bool
{
if (func_num_args() < 3) {
Expand All @@ -55,7 +61,13 @@ public function bindValue($param, $value, $type = ParameterType::STRING): bool
return $this->statement->bindValue($param, $value, $this->convertParamType($type));
}

/** @inheritdoc */
/**
* @throws UnknownParameterType
*
* {@inheritdoc}
*
* @psalm-assert ParameterType::* $type
*/
public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null): bool
{
Deprecation::trigger(
Expand Down Expand Up @@ -108,6 +120,11 @@ public function execute($params = null): Result
return new Result($result, $this->connection->changes());
}

/**
* @psalm-return value-of<self::PARAM_TYPE_MAP>
*
* @psalm-assert ParameterType::* $type
*/
private function convertParamType(int $type): int
{
if (! isset(self::PARAM_TYPE_MAP[$type])) {
Expand Down
9 changes: 5 additions & 4 deletions src/DriverManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ final class DriverManager
*
* @deprecated Use actual driver names instead.
*
* @var string[]
* @var array<string, string>
SenseException marked this conversation as resolved.
Show resolved Hide resolved
* @psalm-var array<string, key-of<self::DRIVER_MAP>>
*/
private static array $driverSchemeAliases = [
'db2' => 'ibm_db2',
Expand Down Expand Up @@ -207,10 +208,10 @@ public static function getAvailableDrivers(): array
}

/**
* @param class-string<Driver>|null $driverClass
* @param key-of<self::DRIVER_MAP>|null $driver
*
* @throws Exception
*
* @psalm-assert key-of<self::DRIVER_MAP>|null $driver
* @psalm-assert class-string<Driver>|null $driverClass
*/
private static function createDriver(?string $driver, ?string $driverClass): Driver
{
Expand Down
6 changes: 5 additions & 1 deletion src/Query/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,15 @@ class QueryBuilder

/**
* The type of query this is. Can be select, update or delete.
*
* @psalm-var self::SELECT|self::DELETE|self::UPDATE|self::INSERT
*/
private int $type = self::SELECT;

/**
* The state of the query object. Can be dirty or clean.
*
* @psalm-var self::STATE_*
*/
private int $state = self::STATE_CLEAN;

Expand Down Expand Up @@ -208,6 +212,7 @@ public function getConnection()
* @deprecated The builder state is an internal concern.
*
* @return int Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN.
* @psalm-return self::STATE_*
*/
public function getState()
{
Expand Down Expand Up @@ -413,7 +418,6 @@ public function getSQL()
break;

case self::SELECT:
default:
$sql = $this->getSQLForSelect();
break;
}
Expand Down