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

[MySQLi] Convert private property Statement::$paramTypeMap to class constant PARAM_TYPE_MAP #6004

Merged
merged 1 commit into from
Apr 18, 2023
Merged
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
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