Skip to content

Commit

Permalink
Merge pull request doctrine#10231 from greg0ire/static-analysis-impro…
Browse files Browse the repository at this point in the history
…vements

Make the code easier to statically analyse
  • Loading branch information
greg0ire committed Nov 16, 2022
2 parents 958d0b6 + 843f3c3 commit 1ce806f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
15 changes: 10 additions & 5 deletions lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Expand Up @@ -1574,9 +1574,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 @@ -1631,7 +1631,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 @@ -1653,7 +1653,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 @@ -1897,7 +1903,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 @@ -66,7 +66,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
14 changes: 8 additions & 6 deletions lib/Doctrine/ORM/Query/Expr.php
Expand Up @@ -9,9 +9,9 @@
use function func_get_args;
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 @@ -608,7 +608,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 @@ -620,13 +620,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 @@ -685,7 +685,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
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php
Expand Up @@ -82,7 +82,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
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

0 comments on commit 1ce806f

Please sign in to comment.