Skip to content

Commit

Permalink
Deprecated the usage of number unaware underscore naming strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
lcobucci committed Nov 19, 2019
1 parent 9ccb883 commit 50992ea
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
8 changes: 8 additions & 0 deletions UPGRADE.md
Expand Up @@ -10,6 +10,14 @@ Method `Doctrine\ORM\AbstractQuery#useResultCache()` which could be used for bot
To optimize DB interaction, `Doctrine\ORM\Tools\Pagination\Paginator` no longer fetches identifiers to be able to
perform the pagination with join collections when max results isn't set in the query.

## Deprecated number unaware `Doctrine\ORM\Mapping\UnderscoreNamingStrategy`

In the last patch of the `v2.6.x` series, we fixed a bug that was not converting names properly when they had numbers
(e.g.: `base64Encoded` was wrongly converted to `base64encoded` instead of `base64_encoded`).

In order to not break BC we've introduced a way to enable the fixed behavior using a boolean constructor argument. This
argument will be removed in 3.0 and the default behavior will be the fixed one.

## Deprecated: `Doctrine\ORM\AbstractQuery#useResultCache()`

Method `Doctrine\ORM\AbstractQuery#useResultCache()` is deprecated because it is split into `enableResultCache()`
Expand Down
9 changes: 9 additions & 0 deletions lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php
Expand Up @@ -22,12 +22,14 @@

use const CASE_LOWER;
use const CASE_UPPER;
use const E_USER_DEPRECATED;
use function preg_replace;
use function strpos;
use function strrpos;
use function strtolower;
use function strtoupper;
use function substr;
use function trigger_error;

/**
* Naming strategy implementing the underscore naming convention.
Expand Down Expand Up @@ -58,6 +60,13 @@ class UnderscoreNamingStrategy implements NamingStrategy
*/
public function __construct($case = CASE_LOWER, bool $numberAware = false)
{
if (! $numberAware) {
@trigger_error(
'Creating ' . self::class . ' without making it number aware is deprecated and will be removed in Doctrine 3.0.',
E_USER_DEPRECATED
);
}

$this->case = $case;
$this->pattern = $numberAware ? self::NUMBER_AWARE_PATTERN : self::DEFAULT_PATTERN;
}
Expand Down
22 changes: 22 additions & 0 deletions tests/Doctrine/Tests/Mapping/UnderscoreNamingStrategyTest.php
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\Mapping;

use Doctrine\ORM\Mapping\UnderscoreNamingStrategy;
use Doctrine\Tests\VerifyDeprecations;
use PHPUnit\Framework\TestCase;
use const CASE_LOWER;

final class UnderscoreNamingStrategyTest extends TestCase
{
use VerifyDeprecations;

/** @test */
public function checkDeprecationMessage() : void
{
$this->expectDeprecationMessage('Creating Doctrine\ORM\Mapping\UnderscoreNamingStrategy without making it number aware is deprecated and will be removed in Doctrine 3.0.');
new UnderscoreNamingStrategy(CASE_LOWER, false);
}
}

0 comments on commit 50992ea

Please sign in to comment.