Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1ce806f

Browse files
authored
Merge pull request #10231 from greg0ire/static-analysis-improvements
Make the code easier to statically analyse
2 parents 958d0b6 + 843f3c3 commit 1ce806f

5 files changed

Lines changed: 21 additions & 14 deletions

File tree

lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,9 +1574,9 @@ private function isTypedProperty(string $name): bool
15741574
/**
15751575
* Validates & completes the given field mapping based on typed property.
15761576
*
1577-
* @param mixed[] $mapping The field mapping to validate & complete.
1577+
* @param array{fieldName: string, type?: mixed} $mapping The field mapping to validate & complete.
15781578
*
1579-
* @return mixed[] The updated mapping.
1579+
* @return array{fieldName: string, enumType?: string, type?: mixed} The updated mapping.
15801580
*/
15811581
private function validateAndCompleteTypedFieldMapping(array $mapping): array
15821582
{
@@ -1631,7 +1631,7 @@ private function validateAndCompleteTypedFieldMapping(array $mapping): array
16311631
/**
16321632
* Validates & completes the basic mapping information based on typed property.
16331633
*
1634-
* @param mixed[] $mapping The mapping.
1634+
* @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.
16351635
*
16361636
* @return mixed[] The updated mapping.
16371637
*/
@@ -1653,7 +1653,13 @@ private function validateAndCompleteTypedAssociationMapping(array $mapping): arr
16531653
/**
16541654
* Validates & completes the given field mapping.
16551655
*
1656-
* @psalm-param array<string, mixed> $mapping The field mapping to validate & complete.
1656+
* @psalm-param array{
1657+
* fieldName?: string,
1658+
* columnName?: string,
1659+
* id?: bool,
1660+
* generated?: int,
1661+
* enumType?: class-string,
1662+
* } $mapping The field mapping to validate & complete.
16571663
*
16581664
* @return mixed[] The updated mapping.
16591665
*
@@ -1897,7 +1903,6 @@ protected function _validateAndCompleteAssociationMapping(array $mapping)
18971903
* Validates & completes a one-to-one association mapping.
18981904
*
18991905
* @psalm-param array<string, mixed> $mapping The mapping to validate & complete.
1900-
* @psalm-param array<string, mixed> $mapping The mapping to validate & complete.
19011906
*
19021907
* @return mixed[] The validated & completed mapping.
19031908
* @psalm-return array{isOwningSide: mixed, orphanRemoval: bool, isCascadeRemove: bool}

lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class DatabaseDriver implements MappingDriver
6666
/** @var array<string,Table>|null */
6767
private $tables = null;
6868

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

7272
/** @psalm-var array<string, Table> */

lib/Doctrine/ORM/Query/Expr.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
use function func_get_args;
1010
use function implode;
1111
use function is_bool;
12+
use function is_float;
13+
use function is_int;
1214
use function is_iterable;
13-
use function is_numeric;
14-
use function is_string;
1515
use function iterator_to_array;
1616
use function str_replace;
1717

@@ -608,7 +608,7 @@ public function length($x)
608608
/**
609609
* Creates a literal expression of the given argument.
610610
*
611-
* @param mixed $literal Argument to be converted to literal.
611+
* @param scalar $literal Argument to be converted to literal.
612612
*
613613
* @return Expr\Literal
614614
*/
@@ -620,13 +620,15 @@ public function literal($literal)
620620
/**
621621
* Quotes a literal value, if necessary, according to the DQL syntax.
622622
*
623-
* @param mixed $literal The literal value.
623+
* @param scalar $literal The literal value.
624624
*/
625625
private function quoteLiteral($literal): string
626626
{
627-
if (is_numeric($literal) && ! is_string($literal)) {
627+
if (is_int($literal) || is_float($literal)) {
628628
return (string) $literal;
629-
} elseif (is_bool($literal)) {
629+
}
630+
631+
if (is_bool($literal)) {
630632
return $literal ? 'true' : 'false';
631633
}
632634

lib/Doctrine/ORM/Query/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ private function processDeferredNewObjectExpressions(SelectStatement $AST): void
685685
$fromClassName = $AST->fromClause->identificationVariableDeclarations[0]->rangeVariableDeclaration->abstractSchemaName ?? null;
686686

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

lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8282
throw new LogicException("Option 'depth' must contain an integer value");
8383
}
8484

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

8888
if (! defined($hydrationMode)) {

0 commit comments

Comments
 (0)