Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the code easier to statically analyse #10231

Merged
merged 1 commit into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
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.
Copy link
Member Author

@greg0ire greg0ire Nov 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a way to make this multiline and have phpcs be happy with it… it's probably the pipes.

*
* @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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About this, see vimeo/psalm#8703

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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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