Skip to content

Commit

Permalink
Merge pull request doctrine#5956 from derrabus/remove/legacy-api
Browse files Browse the repository at this point in the history
Remove the legacy execution and fetch API
  • Loading branch information
derrabus committed Mar 6, 2023
2 parents 3b68634 + 71168d7 commit b4d73f4
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 375 deletions.
12 changes: 12 additions & 0 deletions UPGRADE.md
Expand Up @@ -8,6 +8,18 @@ awareness about deprecated code.

# Upgrade to 4.0

## BC BREAK: Remove legacy execute and fetch methods.

The following methods have been removed:

* `Result::fetch()`
* `Result::fetchAll()`
* `Connection::exec()`
* `Connection::executeUpdate()`
* `Connection::query()`

Additionally, the `FetchMode` class has been removed.

## BC BREAK: Removed the `url` connection parameter

DBAL ships with a new and configurable DSN parser that can be used to parse a
Expand Down
4 changes: 0 additions & 4 deletions phpstan.neon.dist
Expand Up @@ -63,10 +63,6 @@ parameters:
message: '~^Parameter #1 \$driverOptions of method Doctrine\\DBAL\\Tests\\Functional\\Driver\\Mysqli\\ConnectionTest\:\:getConnection\(\) expects array<string, mixed>, .* given\.$~'
path: tests/Functional/Driver/Mysqli/ConnectionTest.php

-
message: '~^Parameter #1 \$mode of method Doctrine\\DBAL\\Result\:\:fetch(?:All)?\(\) expects 2\|3\|7, 1 given\.$~'
path: tests/Functional/LegacyAPITest.php

# DriverManagerTest::testDatabaseUrl() should be refactored as it's too dynamic.
-
message: '~^Offset string does not exist on array{.+}\.$~'
Expand Down
15 changes: 0 additions & 15 deletions psalm.xml.dist
Expand Up @@ -31,22 +31,8 @@
<file name="src/Driver/OCI8/ConvertPositionalToNamedPlaceholders.php"/>
</errorLevel>
</ConflictingReferenceConstraint>
<DeprecatedClass>
<errorLevel type="suppress">
<!--
TODO: remove in 4.0.0
-->
<referencedClass name="Doctrine\DBAL\FetchMode"/>
</errorLevel>
</DeprecatedClass>
<DeprecatedMethod>
<errorLevel type="suppress">
<!--
This suppression should be removed after 2022
See https://github.com/doctrine/dbal/pull/4317
-->
<file name="tests/Functional/LegacyAPITest.php"/>

<!-- TODO for PHPUnit 10 -->
<referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::withConsecutive"/>
</errorLevel>
Expand Down Expand Up @@ -103,7 +89,6 @@
<errorLevel type="suppress">
<!-- We're testing with invalid input here. -->
<file name="tests/Functional/Driver/Mysqli/ConnectionTest.php"/>
<file name="tests/Functional/LegacyAPITest.php"/>
<file name="tests/Platforms/AbstractPlatformTestCase.php"/>
</errorLevel>
</InvalidArgument>
Expand Down
53 changes: 0 additions & 53 deletions src/Connection.php
Expand Up @@ -1362,57 +1362,4 @@ private function handleDriverException(

return $exception;
}

/**
* BC layer for a wide-spread use-case of old DBAL APIs
*
* @deprecated This API is deprecated and will be removed after 2022
*
* @param array<int, mixed>|array<string, mixed> $params
* @psalm-param WrapperParameterTypeArray $types
*
* @return int|numeric-string
*
* @throws Exception
*/
public function executeUpdate(string $sql, array $params = [], array $types = []): int|string
{
return $this->executeStatement($sql, $params, $types);
}

/**
* BC layer for a wide-spread use-case of old DBAL APIs
*
* @deprecated Use {@see executeQuery()} instead
*/
public function query(string $sql): Result
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4163',
'%s is deprecated, please use executeQuery() instead.',
__METHOD__,
);

return $this->executeQuery($sql);
}

/**
* BC layer for a wide-spread use-case of old DBAL APIs
*
* @deprecated please use {@see executeStatement()} instead
*
* @return int|numeric-string
*/
public function exec(string $sql): int|string
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4163',
'%s is deprecated, please use executeStatement() instead.',
__METHOD__,
);

return $this->executeStatement($sql);
}
}
22 changes: 0 additions & 22 deletions src/FetchMode.php

This file was deleted.

79 changes: 0 additions & 79 deletions src/Result.php
Expand Up @@ -7,12 +7,9 @@
use Doctrine\DBAL\Driver\Exception as DriverException;
use Doctrine\DBAL\Driver\Result as DriverResult;
use Doctrine\DBAL\Exception\NoKeyValue;
use Doctrine\Deprecations\Deprecation;
use LogicException;
use Traversable;

use function array_shift;
use function func_num_args;

class Result
{
Expand Down Expand Up @@ -263,80 +260,4 @@ private function ensureHasKeyValue(): void
throw NoKeyValue::fromColumnCount($columnCount);
}
}

/**
* BC layer for a wide-spread use-case of old DBAL APIs
*
* @deprecated Use {@see fetchNumeric()}, {@see fetchAssociative()} or {@see fetchOne()} instead.
*
* @psalm-param FetchMode::* $mode
*
* @throws Exception
*/
public function fetch(int $mode = FetchMode::ASSOCIATIVE): mixed
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4007',
'%s is deprecated, please use fetchNumeric(), fetchAssociative() or fetchOne() instead.',
__METHOD__,
);

if (func_num_args() > 1) {
throw new LogicException('Only invocations with one argument are still supported by this legacy API.');
}

if ($mode === FetchMode::ASSOCIATIVE) {
return $this->fetchAssociative();
}

if ($mode === FetchMode::NUMERIC) {
return $this->fetchNumeric();
}

if ($mode === FetchMode::COLUMN) {
return $this->fetchOne();
}

throw new LogicException('Only fetch modes declared on Doctrine\DBAL\FetchMode are supported by legacy API.');
}

/**
* BC layer for a wide-spread use-case of old DBAL APIs
*
* @deprecated Use {@see fetchAllNumeric()}, {@see fetchAllAssociative()} or {@see fetchFirstColumn()} instead.
*
* @psalm-param FetchMode::* $mode
*
* @return list<mixed>
*
* @throws Exception
*/
public function fetchAll(int $mode = FetchMode::ASSOCIATIVE): array
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4007',
'%s is deprecated, please use fetchAllNumeric(), fetchAllAssociative() or fetchFirstColumn() instead.',
__METHOD__,
);

if (func_num_args() > 1) {
throw new LogicException('Only invocations with one argument are still supported by this legacy API.');
}

if ($mode === FetchMode::ASSOCIATIVE) {
return $this->fetchAllAssociative();
}

if ($mode === FetchMode::NUMERIC) {
return $this->fetchAllNumeric();
}

if ($mode === FetchMode::COLUMN) {
return $this->fetchFirstColumn();
}

throw new LogicException('Only fetch modes declared on Doctrine\DBAL\FetchMode are supported by legacy API.');
}
}

0 comments on commit b4d73f4

Please sign in to comment.