Skip to content

Commit

Permalink
Merge pull request #6004 from phansys/mysqli_statement
Browse files Browse the repository at this point in the history
[MySQLi] Convert private property `Statement::$paramTypeMap` to class constant `PARAM_TYPE_MAP`
  • Loading branch information
derrabus authored Apr 18, 2023
2 parents 3db3f61 + b973a5f commit 1265f8c
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/Driver/Mysqli/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
{
Expand All @@ -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
{
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 1265f8c

Please sign in to comment.