From c06a5837235ec7631cdc83f07b6aa4a9aa001f40 Mon Sep 17 00:00:00 2001 From: Zuruuh Date: Thu, 14 Dec 2023 11:46:18 +0100 Subject: [PATCH] Changes requested in code review Change unnamed arguments wording to "ordered arguments" instead Change docs wording --- docs/en/reference/dql-doctrine-query-language.rst | 4 ++-- lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php | 10 +++++----- lib/Doctrine/ORM/Query/AST/NamedScalarExpression.php | 2 +- lib/Doctrine/ORM/Query/Parser.php | 2 +- .../Doctrine/Tests/ORM/Functional/NewOperatorTest.php | 8 ++++---- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/en/reference/dql-doctrine-query-language.rst b/docs/en/reference/dql-doctrine-query-language.rst index cb08c79425d..ab8a9177350 100644 --- a/docs/en/reference/dql-doctrine-query-language.rst +++ b/docs/en/reference/dql-doctrine-query-language.rst @@ -584,7 +584,7 @@ And then use the ``NEW`` DQL keyword : Note that you can only pass scalar expressions to the constructor. -The ``NEW`` operator also supports named arguments, similarly to php 8.0 : +The ``NEW`` operator also supports named arguments: .. code-block:: php @@ -592,7 +592,7 @@ The ``NEW`` operator also supports named arguments, similarly to php 8.0 : $query = $em->createQuery('SELECT NEW CustomerDTO(email: e.email, name: c.name, address: a.city) FROM Customer c JOIN c.email e JOIN c.address a'); $users = $query->getResult(); // array of CustomerDTO -Note that you cannot pass unnamed arguments after named ones, just like in php. +Note that you must not pass ordered arguments after named ones. Using INDEX BY ~~~~~~~~~~~~~~ diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index 26f74741b93..54fa2697f06 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -573,22 +573,22 @@ protected function hydrateRowData(array $row, array &$result) $obj = $class->newInstanceArgs($args); } else { $constructor = $class->getConstructor(); - $unnamedArgs = []; + $orderedArgs = []; $constructorArguments = $constructor->getParameters(); $constructorArgumentsCount = count($constructorArguments); foreach ($constructorArguments as $argument) { if (array_key_exists($argument->getName(), $args)) { - $unnamedArgs[$argument->getPosition()] = $args[$argument->getName()]; + $orderedArgs[$argument->getPosition()] = $args[$argument->getName()]; } elseif (array_key_exists($argument->getPosition(), $args)) { - $unnamedArgs[$argument->getPosition()] = $args[$argument->getPosition()]; + $orderedArgs[$argument->getPosition()] = $args[$argument->getPosition()]; } else { - $unnamedArgs[$argument->getPosition()] = $argument->getDefaultValue(); + $orderedArgs[$argument->getPosition()] = $argument->getDefaultValue(); } } - $obj = $class->newInstanceArgs($unnamedArgs); + $obj = $class->newInstanceArgs($orderedArgs); } if ($scalarCount === 0 && count($rowData['newObjects']) === 1) { diff --git a/lib/Doctrine/ORM/Query/AST/NamedScalarExpression.php b/lib/Doctrine/ORM/Query/AST/NamedScalarExpression.php index ce42adb35f7..5afc4107050 100644 --- a/lib/Doctrine/ORM/Query/AST/NamedScalarExpression.php +++ b/lib/Doctrine/ORM/Query/AST/NamedScalarExpression.php @@ -9,7 +9,7 @@ class NamedScalarExpression extends Node /** @var Node */ public $innerExpression; - /** @var ?string */ + /** @var string|null */ public $name; public function __construct(Node $scalarExpression, ?string $name = null) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 44d1e86015b..7cd5446f69b 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -1968,7 +1968,7 @@ public function NewObjectArg(/* bool $namedArgAlreadyParsed = false */) } if ($namedArgAlreadyParsed) { - throw QueryException::syntaxError('Cannot specify unnamed arguments after named ones.'); + throw QueryException::syntaxError('Cannot specify ordered arguments after named ones.'); } if ($token->type === Lexer::T_OPEN_PARENTHESIS && $peek->type === Lexer::T_SELECT) { diff --git a/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php b/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php index 74f8abe573f..7721c7eb112 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php @@ -1112,7 +1112,7 @@ public static function provideQueriesWithNamedArguments(): array ORDER BY u.name', ], - 'Both named and unnamed arguments' => [ + 'Both named and ordered arguments' => [ 'SELECT new Doctrine\Tests\Models\CMS\CmsUserDTO( u.name, @@ -1128,7 +1128,7 @@ public static function provideQueriesWithNamedArguments(): array ORDER BY u.name', ], - 'Both named and unnamed arguments without trailing comma' => [ + 'Both named and ordered arguments without trailing comma' => [ 'SELECT new Doctrine\Tests\Models\CMS\CmsUserDTO( u.name, @@ -1176,7 +1176,7 @@ public function testQueryWithNamedArguments(string $query): void self::assertNull($result[2]->phonenumbers); } - public function testQueryWithUnnamedArgumentAfterNamedArgument(): void + public function testQueryWithOrderedArgumentAfterNamedArgument(): void { $dql = ' SELECT @@ -1196,7 +1196,7 @@ public function testQueryWithUnnamedArgumentAfterNamedArgument(): void $query = $this->_em->createQuery($dql); $this->expectException(QueryException::class); - $this->expectExceptionMessage('[Syntax Error] Cannot specify unnamed arguments after named ones.'); + $this->expectExceptionMessage('[Syntax Error] Cannot specify ordered arguments after named ones.'); $query->getResult(); }