Skip to content

Commit

Permalink
Merge branch '4.3.x' into 5.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Dec 27, 2024
2 parents d3fcbcf + d00d5c5 commit 5b1b344
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 4 deletions.
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ all drivers and middleware.

# Upgrade to 4.3

## Deprecated `AbstractAsset::getQuotedName()`

The `AbstractAsset::getQuotedName()` method has been deprecated. Use `NamedObject::getObjectName()` or
`OptionallyQualifiedName::getObjectName()` followed by `Name::toSQL()` instead.

## Deprecated `AbstractAsset` namespace-related methods and property

The following namespace-related methods and property have been deprecated:
Expand Down
6 changes: 6 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
-->
<referencedMethod name="Doctrine\DBAL\Schema\AbstractAsset::getNameParser" />
<referencedMethod name="Doctrine\DBAL\Schema\AbstractAsset::setName" />

<!--
https://github.com/doctrine/dbal/pull/6674
TODO: remove in 5.0.0
-->
<referencedMethod name="Doctrine\DBAL\Schema\AbstractAsset::getQuotedName" />
</errorLevel>
</DeprecatedMethod>
<DocblockTypeContradiction>
Expand Down
11 changes: 11 additions & 0 deletions src/Schema/AbstractAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Doctrine\DBAL\Schema\Name\OptionallyQualifiedName;
use Doctrine\DBAL\Schema\Name\Parser;
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
use Doctrine\Deprecations\Deprecation;

use function array_map;
use function assert;
Expand Down Expand Up @@ -148,9 +149,19 @@ public function getName(): string
/**
* Returns the quoted representation of this asset's name. If the name is unquoted, it is normalized according to
* the platform's unquoted name normalization rules.
*
* @deprecated Use {@see NamedObject::getObjectName()} or {@see OptionallyQualifiedName::getObjectName()} followed
* by {@see Name::toSQL()} instead.
*/
public function getQuotedName(AbstractPlatform $platform): string
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6674',
'%s is deprecated and will be removed in 5.0.',
__METHOD__,
);

$parts = array_map(static function (Identifier $identifier) use ($platform): string {
$value = $identifier->getValue();

Expand Down
7 changes: 7 additions & 0 deletions src/Schema/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@

namespace Doctrine\DBAL\Schema;

use Doctrine\DBAL\Platforms\AbstractPlatform;

/**
* Represents a database object name.
*/
interface Name
{
/**
* Returns the SQL representation of the name for the given platform.
*/
public function toSQL(AbstractPlatform $platform): string;

/**
* Returns the string representation of the name.
*
Expand Down
17 changes: 13 additions & 4 deletions src/Schema/Name/AbstractName.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\DBAL\Schema\Name;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Name;

use function array_map;
Expand All @@ -25,11 +26,19 @@ public function __construct(Identifier $firstIdentifier, Identifier ...$otherIde
$this->identifiers = array_merge([$firstIdentifier], array_values($otherIdentifiers));
}

public function toSQL(AbstractPlatform $platform): string

Check warning on line 29 in src/Schema/Name/AbstractName.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/Name/AbstractName.php#L29

Added line #L29 was not covered by tests
{
return $this->joinIdentifiers(static fn (Identifier $identifier): string => $identifier->toSql($platform));

Check warning on line 31 in src/Schema/Name/AbstractName.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/Name/AbstractName.php#L31

Added line #L31 was not covered by tests
}

public function toString(): string
{
return implode('.', array_map(
static fn (Identifier $identifier): string => $identifier->toString(),
$this->identifiers,
));
return $this->joinIdentifiers(static fn (Identifier $identifier): string => $identifier->toString());
}

/** @param callable(Identifier): string $mapper */
private function joinIdentifiers(callable $mapper): string
{
return implode('.', array_map($mapper, $this->identifiers));
}
}
12 changes: 12 additions & 0 deletions src/Schema/Name/Identifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\DBAL\Schema\Name;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Exception\InvalidIdentifier;

use function sprintf;
Expand Down Expand Up @@ -34,6 +35,17 @@ public function isQuoted(): bool
return $this->isQuoted;
}

public function toSql(AbstractPlatform $platform): string

Check warning on line 38 in src/Schema/Name/Identifier.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/Name/Identifier.php#L38

Added line #L38 was not covered by tests
{
if (! $this->isQuoted) {
$value = $platform->normalizeUnquotedIdentifier($this->value);

Check warning on line 41 in src/Schema/Name/Identifier.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/Name/Identifier.php#L40-L41

Added lines #L40 - L41 were not covered by tests
} else {
$value = $this->value;

Check warning on line 43 in src/Schema/Name/Identifier.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/Name/Identifier.php#L43

Added line #L43 was not covered by tests
}

return $platform->quoteSingleIdentifier($value);

Check warning on line 46 in src/Schema/Name/Identifier.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/Name/Identifier.php#L46

Added line #L46 was not covered by tests
}

public function toString(): string
{
if (! $this->isQuoted) {
Expand Down

0 comments on commit 5b1b344

Please sign in to comment.