From b973a5f1120cea5ebf982e8ce10acfdb27b981ab Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Tue, 11 Apr 2023 21:15:30 -0300 Subject: [PATCH] Convert private property `Statement::$paramTypeMap` to class constant `PARAM_TYPE_MAP` --- src/Driver/Mysqli/Statement.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Driver/Mysqli/Statement.php b/src/Driver/Mysqli/Statement.php index 7b7c93129b3..b8f1961c893 100644 --- a/src/Driver/Mysqli/Statement.php +++ b/src/Driver/Mysqli/Statement.php @@ -27,8 +27,7 @@ final class Statement implements StatementInterface { - /** @var string[] */ - private static array $paramTypeMap = [ + private const PARAM_TYPE_MAP = [ ParameterType::ASCII => 's', ParameterType::STRING => 's', ParameterType::BINARY => 's', @@ -63,9 +62,11 @@ public function __construct(mysqli_stmt $stmt) } /** + * @deprecated Use {@see bindValue()} instead. + * * {@inheritdoc} * - * @deprecated Use {@see bindValue()} instead. + * @psalm-assert ParameterType::* $type */ public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null): bool { @@ -87,18 +88,20 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le ); } - if (! isset(self::$paramTypeMap[$type])) { + if (! isset(self::PARAM_TYPE_MAP[$type])) { throw UnknownParameterType::new($type); } $this->boundValues[$param] =& $variable; - $this->types[$param - 1] = self::$paramTypeMap[$type]; + $this->types[$param - 1] = self::PARAM_TYPE_MAP[$type]; return true; } /** * {@inheritdoc} + * + * @psalm-assert ParameterType::* $type */ public function bindValue($param, $value, $type = ParameterType::STRING): bool { @@ -113,13 +116,13 @@ public function bindValue($param, $value, $type = ParameterType::STRING): bool ); } - if (! isset(self::$paramTypeMap[$type])) { + if (! isset(self::PARAM_TYPE_MAP[$type])) { throw UnknownParameterType::new($type); } $this->values[$param] = $value; $this->boundValues[$param] =& $this->values[$param]; - $this->types[$param - 1] = self::$paramTypeMap[$type]; + $this->types[$param - 1] = self::PARAM_TYPE_MAP[$type]; return true; } @@ -173,10 +176,10 @@ private function bindTypedParameters(): void assert(is_int($parameter)); if (! isset($types[$parameter - 1])) { - $types[$parameter - 1] = self::$paramTypeMap[ParameterType::STRING]; + $types[$parameter - 1] = self::PARAM_TYPE_MAP[ParameterType::STRING]; } - if ($types[$parameter - 1] === self::$paramTypeMap[ParameterType::LARGE_OBJECT]) { + if ($types[$parameter - 1] === self::PARAM_TYPE_MAP[ParameterType::LARGE_OBJECT]) { if (is_resource($value)) { if (get_resource_type($value) !== 'stream') { throw NonStreamResourceUsedAsLargeObject::new($parameter); @@ -187,7 +190,7 @@ private function bindTypedParameters(): void continue; } - $types[$parameter - 1] = self::$paramTypeMap[ParameterType::STRING]; + $types[$parameter - 1] = self::PARAM_TYPE_MAP[ParameterType::STRING]; } $values[$parameter] = $value;