Skip to content

Commit

Permalink
Merge pull request #4920 from kamil-tekiela/Remove-redundant-result-f…
Browse files Browse the repository at this point in the history
…oreach

Remove redundant code in mysqli Result
  • Loading branch information
morozov authored Oct 25, 2021
2 parents 96125a3 + 5570320 commit 8d66218
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
5 changes: 5 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,10 @@ parameters:
message: '~Only numeric types are allowed in \-, float\|null given on the right side\.~'
path: src/Logging/DebugStack.php

# https://github.com/phpstan/phpstan-src/pull/731
-
message: '~Parameter #1 \$array of function array_column expects array, array\|false given\.~'
path: src/Driver/Mysqli/Result.php

includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
18 changes: 4 additions & 14 deletions src/Driver/Mysqli/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@
use Doctrine\DBAL\Driver\Result as ResultInterface;
use mysqli_sql_exception;
use mysqli_stmt;
use stdClass;

use function array_column;
use function array_combine;
use function array_fill;
use function array_map;
use function assert;
use function count;
use function is_array;

final class Result implements ResultInterface
{
Expand Down Expand Up @@ -60,12 +57,7 @@ public function __construct(mysqli_stmt $statement)

$this->hasColumns = true;

$fields = $meta->fetch_fields();
assert(is_array($fields));

$this->columnNames = array_map(static function (stdClass $field): string {
return $field->name;
}, $fields);
$this->columnNames = array_column($meta->fetch_fields(), 'name');

$meta->free();

Expand All @@ -87,10 +79,8 @@ public function __construct(mysqli_stmt $statement)
// to the length of the ones fetched during the previous execution.
$this->boundValues = array_fill(0, count($this->columnNames), null);

$refs = [];
foreach ($this->boundValues as &$value) {
$refs[] =& $value;
}
// The following is necessary as PHP cannot handle references to properties properly
$refs = &$this->boundValues;

if (! $this->statement->bind_result(...$refs)) {
throw StatementError::new($this->statement);
Expand Down

0 comments on commit 8d66218

Please sign in to comment.