Skip to content

Commit

Permalink
Add the getColumnName() method to the Result interface (#6452)
Browse files Browse the repository at this point in the history
|      Q       |   A
|------------- | -----------
| Type         | improvement
| Fixed issues | Follows #6428

#### Summary

Following #6428, the new `getColumnName()` method becomes mandatory with
this PR for all `Result` implementations.
  • Loading branch information
derrabus authored Jun 19, 2024
1 parent 315de17 commit 6424242
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 29 deletions.
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ awareness about deprecated code.

# Upgrade to 5.0

## BC BREAK: Add `Result::getColumnName()`

A new method `getColumnName()` has been added to the `Result` interface and must be implemented by
all drivers and middleware.

## BC BREAK: Removed support for MariaDB 10.4 and MySQL 5.7

* Upgrade to MariaDB 10.5 or later.
Expand Down
4 changes: 0 additions & 4 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ parameters:
-
message: '#^Parameter \#2 \$callback of function array_reduce expects callable\(\(callable&TIn\)\|Closure\(mixed \$value\)\: mixed\|null, callable\(T\)\: T\)\: \(\(callable&TIn\)\|Closure\(mixed \$value\)\: mixed\|null\), Closure\(callable\|null, callable\)\: \(callable\(T\)\: T\) given\.$#'
path: src/Portability/Converter.php

# Type check for legacy implementations of the Result interface
# TODO: remove in 5.0.0
- '~^Call to function method_exists\(\) with Doctrine\\DBAL\\Driver\\Result and ''getColumnName'' will always evaluate to true\.$~'
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
Expand Down
12 changes: 0 additions & 12 deletions src/Driver/Middleware/AbstractResultMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
namespace Doctrine\DBAL\Driver\Middleware;

use Doctrine\DBAL\Driver\Result;
use LogicException;

use function get_debug_type;
use function method_exists;
use function sprintf;

abstract class AbstractResultMiddleware implements Result
{
Expand Down Expand Up @@ -68,13 +63,6 @@ public function columnCount(): int

public function getColumnName(int $index): string
{
if (! method_exists($this->wrappedResult, 'getColumnName')) {
throw new LogicException(sprintf(
'The driver result %s does not support accessing the column name.',
get_debug_type($this->wrappedResult),
));
}

return $this->wrappedResult->getColumnName($index);
}

Expand Down
7 changes: 5 additions & 2 deletions src/Driver/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

/**
* Driver-level statement execution result.
*
* @method string getColumnName(int $index)
*/
interface Result
{
Expand Down Expand Up @@ -88,6 +86,11 @@ public function rowCount(): int|string;
*/
public function columnCount(): int;

/**
* Returns the name of the column in the result set for the given 0-based index.
*/
public function getColumnName(int $index): string;

/**
* Discards the non-fetched portion of the result, enabling the originating statement to be executed again.
*/
Expand Down
11 changes: 0 additions & 11 deletions src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@
use Doctrine\DBAL\Driver\Exception as DriverException;
use Doctrine\DBAL\Driver\Result as DriverResult;
use Doctrine\DBAL\Exception\NoKeyValue;
use LogicException;
use Traversable;

use function array_shift;
use function assert;
use function count;
use function get_debug_type;
use function method_exists;
use function sprintf;

class Result
{
Expand Down Expand Up @@ -266,13 +262,6 @@ public function columnCount(): int
*/
public function getColumnName(int $index): string
{
if (! method_exists($this->result, 'getColumnName')) {
throw new LogicException(sprintf(
'The driver result %s does not support accessing the column name.',
get_debug_type($this->result),
));
}

try {
return $this->result->getColumnName($index);
} catch (DriverException $e) {
Expand Down

0 comments on commit 6424242

Please sign in to comment.