8000 Deprecate calling setters without arguments by derrabus · Pull Request #9791 · doctrine/orm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Deprecate calling setters without arguments #9791

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
8000 Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Upgrade to 2.13

## Deprecated calling setters without arguments

The following methods will require an argument in 3.0. Pass `null` instead of
omitting the argument.

* `Doctrine\ORM\Event\OnClassMetadataNotFoundEventArgs::setFoundMetadata()`
* `Doctrine\ORM\AbstractQuery::setHydrationCacheProfile()`
* `Doctrine\ORM\AbstractQuery::setResultCache()`
* `Doctrine\ORM\AbstractQuery::setResultCacheProfile()`

## Deprecated passing invalid fetch modes to `AbstractQuery::setFetchMode()`

Calling `AbstractQuery::setFetchMode()` with anything else than
Expand Down
28 changes: 28 additions & 0 deletions lib/Doctrine/ORM/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use function array_shift;
use function assert;
use function count;
use function func_num_args;
use function in_array;
use function is_array;
use function is_numeric;
Expand Down Expand Up @@ -548,6 +549,15 @@ private function translateNamespaces(Query\ResultSetMapping $rsm): void
public function setHydrationCacheProfile(?QueryCacheProfile $profile = null)
{
if ($profile === null) {
if (func_num_args() < 1) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/9791',
'Calling %s without arguments is deprecated, pass null instead.',
__METHOD__
);
}

$this->_hydrationCacheProfile = null;

return $this;
Expand Down Expand Up @@ -592,6 +602,15 @@ public function getHydrationCacheProfile()
public function setResultCacheProfile(?QueryCachePro 10000 file $profile = null)
{
if ($profile === null) {
if (func_num_args() < 1) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/9791',
'Calling %s without arguments is deprecated, pass null instead.',
__METHOD__
);
}

$this->_queryCacheProfile = null;

return $this;
Expand Down Expand Up @@ -646,6 +665,15 @@ public function setResultCacheDriver($resultCacheDriver = null)
public function setResultCache(?CacheItemPoolInterface $resultCache = null)
{
if ($resultCache === null) {
if (func_num_args() < 1) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/9791',
'Calling %s without arguments is deprecated, pass null instead.',
__METHOD__
);
}

if ($this->_queryCacheProfile) {
$this->_queryCacheProfile = new QueryCacheProfile($this->_queryCacheProfile->getLifetime(), $this->_queryCacheProfile->getCacheKey());
}
Expand Down
12 changes: 12 additions & 0 deletions lib/Doctrine/ORM/Event/OnClassMetadataNotFoundEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

namespace Doctrine\ORM\Event;

use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\Event\ManagerEventArgs;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;

use function func_num_args;

/**
* Class that holds event arguments for a `onClassMetadataNotFound` event.
*
Expand Down Expand Up @@ -41,6 +44,15 @@ public function __construct($className, ObjectManager $objectManager)
*/
public function setFoundMetadata(?ClassMetadata $classMetadata = null)
{
if (func_num_args() < 1) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/9791',
'Calling %s without arguments is deprecated, pass null instead.',
__METHOD__
);
}

$this->foundMetadata = $classMetadata;
}

Expand Down
25 changes: 25 additions & 0 deletions tests/Doctrine/Tests/ORM/AbstractQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,31 @@ public function testItMakesResultCacheProfilesAwareOfTheResultCache(): void
$this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/4620');
}

/**
* @dataProvider provideSettersWithDeprecatedDefault
*/
public function testCallingSettersWithoutArgumentsIsDeprecated(string $setter): void
{
$entityManager = $this->createMock(EntityManagerInterface::class);
$entityManager->method('getConfiguration')->willReturn(new Configuration());
$query = $this->getMockForAbstractClass(AbstractQuery::class, [$entityManager]);

$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/9791');
$query->$setter();
}

/**
* @return array<string, array{string}>
*/
public function provideSettersWithDeprecatedDefault(): array
{
return [
'setHydrationCacheProfile' => ['setHydrationCacheProfile'],
'setResultCache' => ['setResultCache'],
'setResultCacheProfile' => ['setResultCacheProfile'],
];
}

public function testSettingTheResultCacheIsPossibleWithoutCallingDeprecatedMethods(): void
{
$cache = $this->createMock(CacheItemPoolInterface::class);
Expand Down
0