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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/Driver/Mysqli/Statement.php
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 @@
}

/**
* @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 @@
);
}

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 @@
);
}

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 @@
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];

Check warning on line 179 in src/Driver/Mysqli/Statement.php

View check run for this annotation

Codecov / codecov/patch

src/Driver/Mysqli/Statement.php#L179

Added line #L179 was not covered by tests
}

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 @@
continue;
}

$types[$parameter - 1] = self::$paramTypeMap[ParameterType::STRING];
$types[$parameter - 1] = self::PARAM_TYPE_MAP[ParameterType::STRING];
}

$values[$parameter] = $value;
Expand Down