Skip to content

Commit

Permalink
Convert private property Statement::$paramTypeMap to class constant…
Browse files Browse the repository at this point in the history
… `PARAM_TYPE_MAP`
  • Loading branch information
phansys committed Apr 17, 2023
1 parent 3db3f61 commit b973a5f
Showing 1 changed file with 13 additions and 10 deletions.
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 @@ 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];

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 @@ 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 b973a5f

Please sign in to comment.