Skip to content

Commit

Permalink
Don't call deprecated getSQLResultCasing and usesSequenceEmulatedIden…
Browse files Browse the repository at this point in the history
…tityColumns when we know the platform
  • Loading branch information
nicolas-grekas committed Jun 6, 2023
1 parent 6c9b29f commit a7023cb
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/Internal/SQLResultCasing.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;

use function get_class;
use function method_exists;
use function strtolower;
use function strtoupper;
Expand All @@ -26,7 +27,7 @@ private function getSQLResultCasing(AbstractPlatform $platform, string $column):
return strtolower($column);
}

if (method_exists(AbstractPlatform::class, 'getSQLResultCasing')) {
if (0 !== strpos(get_class($platform), 'Doctrine\\DBAL\\Platforms\\') && method_exists(AbstractPlatform::class, 'getSQLResultCasing')) {
return $platform->getSQLResultCasing($column);
}

Expand Down
8 changes: 7 additions & 1 deletion lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Platforms;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\MySqlPlatform as LegacyMySqlPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
Expand Down Expand Up @@ -621,9 +625,11 @@ private function completeIdGeneratorMapping(ClassMetadataInfo $class): void
case ClassMetadata::GENERATOR_TYPE_IDENTITY:
$sequenceName = null;
$fieldName = $class->identifier ? $class->getSingleIdentifierFieldName() : null;
$platform = $this->getTargetPlatform();

// Platforms that do not have native IDENTITY support need a sequence to emulate this behaviour.
if ($this->getTargetPlatform()->usesSequenceEmulatedIdentityColumns()) {
/** @psalm-suppress UndefinedClass, InvalidClass */
if (! $platform instanceof SqlitePlatform && ! $platform instanceof MySQLPlatform && ! $platform instanceof LegacyMySqlPlatform && ! $platform instanceof SQLServerPlatform && $platform->usesSequenceEmulatedIdentityColumns()) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/8850',
Expand Down
3 changes: 3 additions & 0 deletions phpstan-dbal2.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ parameters:
- '/Call to an undefined method Doctrine\\DBAL\\Connection::createSchemaManager\(\)\./'
# Class name will change in DBAL 3.
- '/^Class Doctrine\\DBAL\\Platforms\\PostgreSQLPlatform not found\.$/'
-
message: '/Doctrine\\DBAL\\Platforms\\MyS(ql|QL)Platform/'
path: lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php

# Forward compatibility for DBAL 3.5
- '/^Call to an undefined method Doctrine\\DBAL\\Platforms\\AbstractPlatform::getAlterSchemaSQL\(\).$/'
Expand Down
3 changes: 3 additions & 0 deletions phpstan-persistence2.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ parameters:
- '/^Class Doctrine\\DBAL\\Platforms\\SQLAnywherePlatform not found\.$/'
- '/^Call to method \w+\(\) on an unknown class Doctrine\\DBAL\\Platforms\\SQLAnywherePlatform\.$/'

-
message: '/Doctrine\\DBAL\\Platforms\\MyS(ql|QL)Platform/'
path: lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
-
message: '/^Call to an undefined method Doctrine\\DBAL\\Platforms\\AbstractPlatform::getSQLResultCasing\(\)\.$/'
path: lib/Doctrine/ORM/Internal/SQLResultCasing.php
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ parameters:
- '/^Class Doctrine\\DBAL\\Platforms\\SQLAnywherePlatform not found\.$/'
- '/^Call to method \w+\(\) on an unknown class Doctrine\\DBAL\\Platforms\\SQLAnywherePlatform\.$/'

-
message: '/Doctrine\\DBAL\\Platforms\\MyS(ql|QL)Platform/'
path: lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
-
message: '/^Call to an undefined method Doctrine\\DBAL\\Platforms\\AbstractPlatform::getSQLResultCasing\(\)\.$/'
path: lib/Doctrine/ORM/Internal/SQLResultCasing.php
Expand Down

0 comments on commit a7023cb

Please sign in to comment.