Skip to content

Commit

Permalink
Merge branch '2.14.x' into 3.0.x
Browse files Browse the repository at this point in the history
* 2.14.x:
  Remove fragile assertions (doctrine#10239)
  update help for RunDqlCommand (doctrine#10233)
  Make the code easier to statically analyse
  Widen parameter type
  Document property as non-nullable
  • Loading branch information
derrabus committed Nov 20, 2022
2 parents d6b9da0 + 92489fa commit 5558b54
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 19 deletions.
15 changes: 10 additions & 5 deletions lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Expand Up @@ -1269,9 +1269,9 @@ private function isTypedProperty(string $name): bool
/**
* Validates & completes the given field mapping based on typed property.
*
* @param mixed[] $mapping The field mapping to validate & complete.
* @param array{fieldName: string, type?: mixed} $mapping The field mapping to validate & complete.
*
* @return mixed[] The updated mapping.
* @return array{fieldName: string, enumType?: string, type?: mixed} The updated mapping.
*/
private function validateAndCompleteTypedFieldMapping(array $mapping): array
{
Expand Down Expand Up @@ -1326,7 +1326,7 @@ private function validateAndCompleteTypedFieldMapping(array $mapping): array
/**
* Validates & completes the basic mapping information based on typed property.
*
* @param mixed[] $mapping The mapping.
* @param array{type: self::ONE_TO_ONE|self::MANY_TO_ONE|self::ONE_TO_MANY|self::MANY_TO_MANY, fieldName: string, targetEntity?: class-string} $mapping The mapping.
*
* @return mixed[] The updated mapping.
*/
Expand All @@ -1348,7 +1348,13 @@ private function validateAndCompleteTypedAssociationMapping(array $mapping): arr
/**
* Validates & completes the given field mapping.
*
* @psalm-param array<string, mixed> $mapping The field mapping to validate & complete.
* @psalm-param array{
* fieldName?: string,
* columnName?: string,
* id?: bool,
* generated?: int,
* enumType?: class-string,
* } $mapping The field mapping to validate & complete.
*
* @return mixed[] The updated mapping.
*
Expand Down Expand Up @@ -1580,7 +1586,6 @@ protected function _validateAndCompleteAssociationMapping(array $mapping)
* Validates & completes a one-to-one association mapping.
*
* @psalm-param array<string, mixed> $mapping The mapping to validate & complete.
* @psalm-param array<string, mixed> $mapping The mapping to validate & complete.
*
* @return mixed[] The validated & completed mapping.
* @psalm-return array{isOwningSide: mixed, orphanRemoval: bool, isCascadeRemove: bool}
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php
Expand Up @@ -58,7 +58,7 @@ class DatabaseDriver implements MappingDriver
/** @var array<string,Table>|null */
private $tables = null;

/** @var mixed[] */
/** @var array<class-string, string> */
private $classToTableNames = [];

/** @psalm-var array<string, Table> */
Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/Mapping/MappingException.php
Expand Up @@ -768,7 +768,8 @@ public static function invalidFetchMode(string $className, string $fetchMode): s
return new self("Entity '" . $className . "' has a mapping with invalid fetch mode '" . $fetchMode . "'");
}

public static function invalidGeneratedMode(string $generatedMode): self
/** @param int|string $generatedMode */
public static function invalidGeneratedMode($generatedMode): self
{
return new self("Invalid generated mode '" . $generatedMode . "'");
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Query/AST/WhenClause.php
Expand Up @@ -17,7 +17,7 @@ class WhenClause extends Node
* @param ConditionalExpression $caseConditionExpression
* @param mixed $thenScalarExpression
*/
public function __construct(public $caseConditionExpression = null, public $thenScalarExpression = null)
public function __construct(public $caseConditionExpression, public $thenScalarExpression = null)
{
}

Expand Down
14 changes: 8 additions & 6 deletions lib/Doctrine/ORM/Query/Expr.php
Expand Up @@ -8,9 +8,9 @@

use function implode;
use function is_bool;
use function is_float;
use function is_int;
use function is_iterable;
use function is_numeric;
use function is_string;
use function iterator_to_array;
use function str_replace;

Expand Down Expand Up @@ -600,7 +600,7 @@ public function length($x)
/**
* Creates a literal expression of the given argument.
*
* @param mixed $literal Argument to be converted to literal.
* @param scalar $literal Argument to be converted to literal.
*
* @return Expr\Literal
*/
Expand All @@ -612,13 +612,15 @@ public function literal($literal)
/**
* Quotes a literal value, if necessary, according to the DQL syntax.
*
* @param mixed $literal The literal value.
* @param scalar $literal The literal value.
*/
private function quoteLiteral($literal): string
{
if (is_numeric($literal) && ! is_string($literal)) {
if (is_int($literal) || is_float($literal)) {
return (string) $literal;
} elseif (is_bool($literal)) {
}

if (is_bool($literal)) {
return $literal ? 'true' : 'false';
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Query/Parser.php
Expand Up @@ -684,7 +684,7 @@ private function processDeferredNewObjectExpressions(SelectStatement $AST): void
$fromClassName = $AST->fromClause->identificationVariableDeclarations[0]->rangeVariableDeclaration->abstractSchemaName ?? null;

// If the namespace is not given then assumes the first FROM entity namespace
if (! str_contains($className, '\\') && ! class_exists($className) && str_contains($fromClassName, '\\')) {
if (! str_contains($className, '\\') && ! class_exists($className) && is_string($fromClassName) && str_contains($fromClassName, '\\')) {
$namespace = substr($fromClassName, 0, strrpos($fromClassName, '\\'));
$fqcn = $namespace . '\\' . $className;

Expand Down
20 changes: 18 additions & 2 deletions lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php
Expand Up @@ -38,7 +38,23 @@ protected function configure(): void
->addOption('max-result', null, InputOption::VALUE_REQUIRED, 'The maximum number of results in the result set.')
->addOption('depth', null, InputOption::VALUE_REQUIRED, 'Dumping depth of Entity graph.', 7)
->addOption('show-sql', null, InputOption::VALUE_NONE, 'Dump generated SQL instead of executing query')
->setHelp('Executes arbitrary DQL directly from the command line.');
->setHelp(<<<'EOT'
The <info>%command.name%</info> command executes the given DQL query and
outputs the results:
<info>php %command.full_name% "SELECT u FROM App\Entity\User u"</info>
You can also optionally specify some additional options like what type of
hydration to use when executing the query:
<info>php %command.full_name% "SELECT u FROM App\Entity\User u" --hydrate=array</info>
Additionally you can specify the first result and maximum amount of results to
show:
<info>php %command.full_name% "SELECT u FROM App\Entity\User u" --first-result=0 --max-result=30</info>
EOT
);
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand All @@ -58,7 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
throw new LogicException("Option 'depth' must contain an integer value");
}

$hydrationModeName = $input->getOption('hydrate');
$hydrationModeName = (string) $input->getOption('hydrate');
$hydrationMode = 'Doctrine\ORM\Query::HYDRATE_' . strtoupper(str_replace('-', '_', $hydrationModeName));

if (! defined($hydrationMode)) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php
Expand Up @@ -19,8 +19,8 @@
use Doctrine\ORM\Mapping\MappingException;
use Doctrine\ORM\Mapping\ReflectionEmbeddedProperty;
use Doctrine\ORM\Query\QueryException;
use Doctrine\Persistence\Reflection\RuntimePublicReflectionProperty;
use Doctrine\Tests\OrmFunctionalTestCase;
use ReflectionProperty;

use function class_exists;
use function sprintf;
Expand Down Expand Up @@ -53,7 +53,7 @@ public function testMetadataHasReflectionEmbeddablesAccessible(): void
);
} else {
self::assertInstanceOf(
RuntimePublicReflectionProperty::class,
ReflectionProperty::class,
$classMetadata->getReflectionProperty('address'),
);
}
Expand Down

0 comments on commit 5558b54

Please sign in to comment.